Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a program on many remote hosts these program may run serveral hours and it needs root privilege I have uploaded the program to those remote hosts I can only ssh into those machines with my username but with my username I can sudo without password

now I want to write a automation script to run them on those hosts

basically I need something like:

for remote_host in host_list:
     run the program on remote_host

and then the script quits. I tried

ssh -t usr@remote_host "sudo /home/usr/program"

but this will block my shell until the program quits so I tried

ssh -t usr@remote_host "sudo /home/usr/program" &

it does'nt work, I use ps -ef to check and find no process

I also tried python paramiko, but failed

I also want to log all output from running the program

can anyone give some solutions? thanks

share|improve this question
up vote 4 down vote accepted


ssh -t usr@remote_host 'sudo nohup bash -c "/home/user/program > /dev/null 2>&1 &"'

The nohup should allow your shell to exit without killing the program that you are running. Drop the -t option if you don't want the nohup.out file to be created.

share|improve this answer
Why do you need the “bash -c”? Wouldn’t “sudo nohup /home/user/program …” be just as good? – Scott Apr 18 '13 at 18:39
@Scott: Good question. Seem to need it in order to keep the & from being associated with the nohup. – Jonathan Ben-Avraham Apr 18 '13 at 18:47
If the program intended to run needs tty, e.g., tcpdump, the -t option is necessary, even if you don't want the nohup.out file to be created. – okwap Jan 6 at 8:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .