LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   executing script even when we close connection via ssh (https://www.linuxquestions.org/questions/linux-newbie-8/executing-script-even-when-we-close-connection-via-ssh-4175450668/)

sanaz 02-18-2013 10:14 AM

executing script even when we close connection via ssh
 
Hi all,

I need to run a shell script on e remote machine, my connection is now strong, or I want to shut down my machine. But problem is when I close my connection(or lost it), execution of script is terminated. I googled a lot, I saw using of nohup or screen, but none of them worked for me. I really need to do that.

Any help is appreciated a lot.

suicidaleggroll 02-18-2013 10:19 AM

What did you try?

nohup:
Code:

nohup ./script > script.out 2>&1 &
screen:
Code:

$ screen -S thisismyscreen bash
$ ./script

Then you can use Ctrl+a d to detach from the screen, and "screen -r thisismyscreen" to reattach.

sanaz 02-18-2013 10:46 AM

Thanks a lot for your answer, but is this after I ssh to remote machine?
Could you please explain it more?

and here it is what I am doing:(which does not work at all)
Code:

ssh root@remoteserver screen -d -m ./script

shivaa 02-18-2013 10:57 AM

Better use nohup instead of screen cmd. (See manual here)
Code:

~$ nohup ./script.sh > /path/to/output

sanaz 02-18-2013 11:25 AM

Thanks a lot, it simply worked.

suicidaleggroll 02-18-2013 12:44 PM

Both of my examples are intended to be run after you log in and are sitting at an interactive command prompt on the remote server. Once you run them, you can then log out of SSH and close the terminal without the background process aborting.


All times are GMT -5. The time now is 08:17 PM.