Keep running a script via ssh

5,878

Solution 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 user_name@machine_address "nohup your_script.sh" &

Solution 2

ssh user@server "nohup script.sh >/var/log/output.log 2>&1 &"

That should run the remote command without leaving a running ssh process on your client.

Solution 3

$ ssh [email protected] screen -dm long-script.sh
Share:
5,878

Related videos on Youtube

Arturo Herrero
Author by

Arturo Herrero

Software is my craft.

Updated on September 18, 2022

Comments

  • Arturo Herrero
    Arturo Herrero over 1 year

    ssh can use to run remote commands.

    ssh [email protected] '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?

    • choroba
      choroba over 12 years
      What's wrong with starting screen on the remote server?