Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to run a script on a remote host with sudo privilege, someone suggests that I should use nohup and ssh -t, like the following command:

The script ls; sleep 10; echo finish is crafted here to resemble what I want to do.

ssh -t esolve@remote_host \
'sudo nohup bash -c "ls;sleep 100;echo finish" < /dev/null 2>&1 >> ssh.log' 

I want to run this script in background on local host because in my script, after this command there are some other commands, like

my script.sh:

ssh -t esolve@remote_host \
'sudo nohup bash -c "ls;sleep 100;echo finish" < /dev/null 2>&1 >> ssh.log' 
... some other commands

the following two commands don't work

ssh -t esolve@remote_host \
'sudo nohup bash -c "ls;sleep 100;echo finish" < /dev/null 2>&1 >> ssh.log' &

ssh -t esolve@remote_host \
'sudo nohup bash -c "ls;sleep 100;echo finish" < /dev/null 2>&1 >> ssh.log &' 

Why?

And how can I make this command run in background of local host? Besides, I don't need to input password for sudo on remote host.

share|improve this question
    
Please add some more backround information. Do you want to run it in background of the localhost or remotehost? How are you authenticating with the remotehost, via public key or password? –  vertoe May 9 '13 at 10:37
    
The main problem seems to be how to run this command as superuser in backround without setting a password. Have a look at this: stackoverflow.com/a/4327123/1260906 –  vertoe May 9 '13 at 10:42
    
I have updated the question, thanks –  misteryes May 11 '13 at 19:09
    
You can also use screen to background stuff: screen -d -m -S mybackgroundjob /usr/local/bin/somescript.sh –  jkj May 26 '13 at 1:27

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.