SSH not releasing terminal
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 me@somewhere.com
me@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:
Restart开发者_StackOverflowing nginx daemon: nginx.
me@somewhere:~$ exit
logout
Connection to somewhere.com closed.
~ $ ssh me@somewhere.com 'sudo /etc/init.d/nginx restart'
me@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:~$
Update:
I thought the init script might have a bug in it too. I have since used 3 different versions of an init script for niginx and all 3 have had the same issue. I am currently running this script which seems to be the pick of the 3 I found.
http://wiki.nginx.org/Nginx-init-ubuntu
I just tried the command suggested in the comments, and the issue is exactly the same. Any other ideas?
OK I managed to fix this by forcing pseudo-tty allocation. Simply add the -t option to the SSH command. This fixes the issue and still allows you to see the output. So...
ssh user@my-server 'sudo /etc/init.d/nginx start'
becomes...
ssh -t user@my-server 'sudo /etc/init.d/nginx start'
Short version:
let try this in 2 steps:
- Create a script with your command on your server
- Launch that script from your laptop
Detailed version
On your ubuntu box, create a script (let's say /my/path/nginx-my-start.sh) with this content
sudo /etc/init.d/nginx start 1>/dev/null
Don't forget to give it execution rights (chmod +x /my/path/nginx-my-start.sh)
Then from your laptop, call:
ssh user@my-server /my/path/nginx-my-start.sh
Explanations
I had exactly the same problem with a tomcat I wanted to remotely start. Adding the stdout redirection '1>/dev/null' in the script did the job.
精彩评论