Mount get's undone when script ends?

I often mount remote directories, and thought I’d make my workflow more efficient by creating application shortcuts for mounts. Because I wasn’t successful at first, I’ve came up with this bash script which I’m executing using an application shortcut:

#!/bin/bash
echo "commencing mount"
sshfs -v -o ServerAliveInterval=15 server:/ /mnt/target/
echo "mount done!"
read

My shortcut (*.desktop) definition looks like this:

[Desktop Entry]
Comment[en_US]=
Comment=
Exec=/home/user/Scripts/SSHFS-mount-server.sh
GenericName[en_US]=
GenericName=
MimeType=
Name[en_US]=server sshfs
Name=server sshfs
NoDisplay=false
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Since adding the read statement I found that the mount is actually working, but strangely it get’s auto-unmounted as soon as the script ends, which is very much different from the behavior I’m used to, namely the mount staying mounted until I unmount it again.

What’s going on here? Can I make the mount stick without blocking the calling script from ending (and keeping the Konsole window started for it open)?

It ends because it’s running in a script, and therefore a subshell. You have to use nohup if you want it to persist when the script ends.

man nohup
1 Like

but running the same script manually makes the mount persist? even if I quit the terminal window and start a new one? mounting directories usually doesn’t require the calling session to remain open, at least that has been my experience?

Then you’re running it in the current shell.

I don’t have much experience with sshfs, but it’s possible that it detaches itself only from the shell it has been invoked with. However, if that shell is itself a subshell of another shell, then it most likely terminates due to a broken socket. It is after all a network connection.

1 Like

ah, that explains it, thanks! using nohup does the trick and makes the mount stick, thank you! :slight_smile:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.