Kicking off background jobs over SSH

I needed this information yesterday, as I was trying to use SSH from one machine to start a shell script running in the background on another.

You’re probably using the OpenSSH server, and started a background process on the server which you intended to continue after logging out of the SSH session. Fix: redirect the background process stdin/stdout/stderr streams (e.g. to files, or /dev/null if you don’t care about them).

Works perfectly. So, not this:

ssh remotehost "script.sh &"

but this:

ssh remotehost "nohup script.sh < /dev/null >script.out 2>script.err &"

This is also needed for pssh.

pssh -h remotehosts.txt "nohup script.sh < /dev/null >script.out 2>script.err &"
Advertisements

One thought on “Kicking off background jobs over SSH

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s