1835031 Members
2335 Online
110073 Solutions
New Discussion

ssh and nohup question

 
Wood_2
Frequent Advisor

ssh and nohup question

I would like to start a background process on a distant server through ssh, like

ssh remote "/home/root/script.sh"

the shell script contain something like

nohup ./example &

the problem on the distant server, I have no response from the execution of the script.

And I'm waiting, waiting.

Have you an idea ?
10 REPLIES 10
Christian Tremblay
Trusted Contributor

Re: ssh and nohup question

The problem is that by using nohup on the remote server, the output of your script will go to a nohup.out file on it.

I did not test it, but you may try something like:

ssh remote "/home/root/script.sh;tail -f /home/root/nohup.out"
Wood_2
Frequent Advisor

Re: ssh and nohup question

I don't understand.

I wouldn't the output of the command.

Just the simple execution of the script, with no wait.
Peter Nikitka
Honored Contributor

Re: ssh and nohup question

Hi,

what output do you expect?
Try this script ~/bin/chkit:

#!/usr/bin/ksh

echo output $1
if [ $# -gt 0 ]
then sleep $1
else
nohup $0 15 >/tmp/tt$$ &
fi

echo fini $1
[ -s /tmp/tt$$ ] && cat /tmp/tt$$

Run
ssh hostname ~/bin/chkit
You won't see the output of the nohup process on the screen but in the file, since it is not ready at the time the 'cat' ist performed.


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Wood_2
Frequent Advisor

Re: ssh and nohup question

My vocabulary is poor sorry.

The problem is with the ssh command.

The ssh are waiting the end of nohup and backrgound command.

The ssh command never qive the hand, no answer.

I need to make ctrl c, to stop the command.

On the remote server, the scipt was successfuly executed but have sended no answer ssh father process.

I hope you have understand my problem

Christian Tremblay
Trusted Contributor

Re: ssh and nohup question

Check the -f and -n options of ssh

or use nohup ssh remote "/home/root/script.sh"
Peter Nikitka
Honored Contributor

Re: ssh and nohup question

Hi,

please try uf ssh succesful in executing
ssh otherhost ls -x

If okay, try
ssh -n otherhost /home/root/script.sh
else
ssh -v otherhost ls -x

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Wood_2
Frequent Advisor

Re: ssh and nohup question

It's better with the -f option.

But I need to press enter after the start of the process to go back to the shell.

The ssh command, is into a web page, so couldn't press enter.
Peter Nikitka
Honored Contributor

Re: ssh and nohup question

Hi,

is there a difference when you do not a
nohup ./example &
but just a plain call to
./example

in "/home/root/script.sh"?
Is there the need to press return as well?

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Wood_2
Frequent Advisor

Re: ssh and nohup question

I've solved my problem.

The launch script was into php script.

the command line was

exec("ssh root@hostname /script.sh);

I've remplaced the exec command, with popen function.

And now it works fine.

Thank you all for your help.
Wood_2
Frequent Advisor

Re: ssh and nohup question

see the post before