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

#!/bin/sh
sudo service tomcat start
read

(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 test.sh script, but I can't seem to get it working.

ssh -t gregb@111.111.111.111 "/root/bin/test.sh"
ssh -t gregb@111.111.111.111 "nohup /root/bin/test.sh"
ssh -t gregb@111.111.111.111 "nohup /root/bin/test.sh &"
ssh -t gregb@111.111.111.111 "screen /root/bin/test.sh &"
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
add comment

1 Answer

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  10.3.0.7 screen -dmS foobar
ssh -l jaroslav  10.3.0.7 screen -S foobar -X stuff top^M

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

# to resume
ssh -t -l jaroslav 10.3.0.7 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
add comment

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.