Tuesday, 24 April 2018

linux - Continue SSH background task/jobs when closing SSH


I have the same question as here but even beyond that.


If I logout/exit the SSH connection, I need my program running in background. Before exit, I type bg and jobs to check background running task, but after exiting SSH, the program doesn't run, it closes when I close the SSH window.


What can I do if I want my program still running after closing the SSH window? I do use nohup screen but it also doesn't work, or am I missing something?



Answer



When you use screen you need to detach with CTRL+A+D before you exit ssh.


Alternatively, if you want to run a process directly with screen you can use


screen -dmSL [session name] [commands]


  • -d starts a screen session and immediately detaches from it

  • -m forces creating a new screen session

  • -S lets you give the session a name

  • -L turns on logging to ~/screenlog.0


example:


screen -dmSL workstuff myscript.sh

You can then either:


resume later using screen -x workstuff


or


check the log file less -r ~/screenlog.0


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...