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 have a service (tomcat) that needs sudo to be started. I made a simple script on the remote server in /root/bin/

sudo service tomcat start

(The script needs to do other stuff too, just pared down for simplicity). When I run a it directly on the remote server, tomcat starts and continues running on the server after I disconnect.

When I run it remotely, the process starts, (I can see it when paused for the "read"), but once the script ends, it's gone. (while paused for the read, run this command locally)

ps -ef | grep tomcat

I've tried various combinations of nohup, screen, and & on the commands both on the local machine and in the remote machine's script, but I can't seem to get it working.

ssh -t gregb@ "/root/bin/"
ssh -t gregb@ "nohup /root/bin/"
ssh -t gregb@ "nohup /root/bin/ &"
ssh -t gregb@ "screen /root/bin/ &"
share|improve this question
Have you already checked (in /var/log/syslog e.g.) if the service stops because errors are encountered? – ott-- May 18 '12 at 18:23

Start a screen session in the background and run your script in it. This works for me with top which is interactive "like sudo".

ssh -l jaroslav screen -dmS foobar
ssh -l jaroslav screen -S foobar -X stuff top^M

# ^M means [return]
#ssh -l jaroslav screen -S foobar -X stuff top
#ssh -l jaroslav screen -S foobar -X stuff $'\015'

# to resume
ssh -t -l jaroslav screen -r -S foobar

To be honest, this is kind of a backwards way to start a service, but I'm not exactly sure why tomcat is terminated when you ssh into the box with ssh -t. After all, the service runs in the background, right?

share|improve this answer

You must log in to answer this question.

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