1

I have an SMB share mounted through nautilus. I am noticing that the gnome-screenshot tool seems to be able to access this mounted share automatically, as I do not get any password prompt when running the following:

gnome-screenshot -w -f "smb://<server>/<share>/path/image.png" 

This works and I see the uploaded screenshot.

I would then like to create/upload a text file from a bash variable with no user interaction, but I am unhappy with the solutions I have come up with so far:

  • echo directly into the mountpoint of the share (/run/user/XXXX/gvfs/...)
    • I don't love having long hardcoded paths that contain userIDs and server addresses that may change, however unlikely
  • Use smbclient to put a copy of the file after creating it locally
    • Requires me to either enter credentials again, or store it in the bash file

Is there a way to make smbclient recognize the already mounted share without re-entering credentials, or is there another tool like gnome-screenshot that would allow me to accomplish similar functionality with a text file?

Or, is the ugly mountpoint solution the best there is?

1 Answer 1

2

I have an SMB share mounted through nautilus. I am noticing that the gnome-screenshot tool seems to be able to access this mounted share automatically, as I do not get any password prompt when running the following

yep, GNOME tools use the gvfs virtual filesystem implementation, which will mount things on the fly and get credentials from gnome-keyring if necessary and possible.

So all you need to do is find another gvfs client that lets you store data. I'm not sure whether you want a text editor, because then, the standard GNOME text editor can absolutely do that, gedit smb://….

Another option for creating the file without user interaction is the gio (Gnome Input/Output) tool, which has a save subcommand that saves data from stdin. This can be used with echo to save the contents of a variable:

echo $output | gio save "smb://server/share/test.txt" 
3
  • I edited my question to specify, i was looking for a tool to create a text file with no user interaction/UI (from a bash variable). I was able to find gio {save, move} which i have never used before, but worked perfectly for my application. If you could edit your answer to include mention of the gio tool i would appreciate it, but as is you provided the context needed for me to find a solution so i will accept it. Thanks! Commented Jan 12 at 7:27
  • @DouglasB but I already do mention the gio tool? Commented Jan 12 at 11:44
  • Yes I slightly misspoke, the part of the answer that I felt needed clarification was mentioning gio mount vs gio save in the context of the question. I have edited the answer to include an example of the command which solved my problem, I hope you do not mind! Commented Jan 13 at 19:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.