1

I'm trying to use the "Run Script Over SSH" in Shortcuts (found under Scripting > Shell.

I want to execute a long running command from a sharesheet. So that the sharesheet doesn't remain open, and I can move on to other tasks without worrying about leaving the network etc, the command, foo, needs to execute detached from the SSH session.

I have tried using nohup, but I receive a nohup: can't detach from console: Undefined error: 0. I have also tried backgrouding & and using disown, but neither technique has been successful. Also tried screen on my machine, but it just hangs blank. Are these ineffective because of security changes to MacOS?

What is the appropriate way to keep foo running after my ssh session is gone?

3 Answers 3

1

Try using tmux it'll keep sessions alive after you leave.

1

I use the GNU screen for this purpose.

For macOS host,

screen -dm zsh -c "your scripts"

For linux host,

screen -dm bash -c "your scripts"

According to GNU screen man page,

   -d -m   Start screen in detached mode. This creates a new session but doesn't attach to it.
          This is useful for system startup scripts.

The side effect is that the screen process may still be alive even after the job is done for some commands if zombie kr is in ~/.screenrc. You can check it with ps aux | grep -i screen.

e.g.

screen -dm bash -c "/usr/bin/yt-dlp -q -o '/mnt/drive_name/youtube/%(title.0:60)s.%(ext)s' 'youtube urls'"
0

I ended up using:

screen -S myScreen
/usr/local/bin/myScript "Shortcut Input" < /dev/null > /dev/null 2>&1 &
screen -d myScreen
exit

My command needed to be attached to an input and it was not running when it would detach with a regular screen C-a D

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .