ssh can use to run remote commands.
ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0cdc5e0d3c5d2d6c5d28ec3cfcd">[email protected]</a> 'long-script.sh'
I run a long script that will take a lot of time, but I want to close my computer and keep running the script in the remote server. I know how to achieve this with GNU Screen, but I need do it via ssh.
Can I do that without interrupting my script?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use “nohup” to run a command immune to hangups, with output to a non-tty:
nohup your_command &
and to run a command via ssh, without first logging into the remote machine:
ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53262036210c3d323e36133e32303b3a3d36">[email protected]</a>_address "nohup your_script.sh" &
Method 2
$ ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="402d25003325323625326e232f2d">[email protected]</a> screen -dm long-script.sh
Method 3
ssh [email protected] "nohup script.sh >/var/log/output.log 2>&1 &"
That should run the remote command without leaving a running ssh process on your client.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0