Tag Archives: bash

My getopts reference page

I don’t use bash getopts often enough to remember its syntax exactly. I can’t just say man getopts or info getopts to see its man page, and while¬†this tutorial is good, it’s not as straightforward as I’d prefer. So here’s my reference page. Continue reading

Advertisements

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 &"