Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 http://stackoverflow.com/questions/16085502/run-remote-program-with-root-priviledge-using-paramiko-ssh-channel

I also want to log all output from running the program

can anyone give some solutions? thanks

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Try:

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
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.