When I run the following command from my macbook to my ubuntu server
the terminal does not get released. It just sits there until I Control-
C the command.
ssh user@my-server 'sudo /etc/init.d/nginx start'
When i login and then run the command everything works fine.
ssh user@my-server
sudo /etc/init.d/nginx start
Here is the output highlighting the issue
~ $ ssh m...@somewhere.com
m...@somewhere.com's password:
Last login: Mon Sep 6 15:18:18 2010 from
me@somewhere:~$ sudo /etc/init.d/nginx restart
[sudo] password for me:
Restarting nginx daemon: nginx.
me@somewhere:~$ exit
logout
Connection to somewhere.com closed.
~ $ ssh m...@somewhere.com 'sudo /etc/init.d/nginx restart'
m...@somewhere.com's password:
[sudo] password for me:
Restarting nginx daemon: nginx.
After the last command executes it just holds there and does nothing.
Thanks in advance for any advice you might have.
me@somewhere:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.4 LTS"
me@somewhere:~$
That happens whenever I use SSH to run anything in background.
The Solaris man page says this:
-n
Redirects stdin from /dev/null (actually, prevents read-
ing from stdin). This must be used when ssh is run in
the background ...
I've used -n but it doesn't work all of the time. Unless I know the
background job will use noup I also include nohup inside the quoted
command string. All of the init start scripts I have read use nohup.
Adding the nohup to anything that doesn't already include it fixes that.
Hi Doug,
Thanks for the reply. Tried adding -n and nohup but the issue still
remains. Any more advice?
ssh user@my-server sudo "/etc/init.d/nginx start' >/dev/null 2>/dev/
null </dev/null"
That should direct stdin, stdout, and stderr after you've successfully
committed your sudo, I think.