DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2012-11-11 20:34:59

rspitz
Member
Registered: 2012-10-13
Posts: 12

nohup doesn't work in script started via ssh

Hi,

I'm running FFP 0.7 on my Medion NAS (Oxnas based), which works great!

I have a script on the NAS which contains a command that is started with "nohup". Everything works as expected when the script is started locally (in an interactive ssh session), but when I invoke this script from a remote machine with ssh, the nohuped command exits when the script exits.

I've googled for a solution, and tried different suggestions like explicitly redirecting stdout, stderr and stdin in the nohuped command, and invoking ssh with the "-n" option, but nothing works.

Is there anything special about the nohup command included in FFP 0.7 that I should know about?

Regards, Richard

Offline

 

#2 2012-11-12 17:41:34

memiks
Member
Registered: 2011-09-02
Posts: 72

Re: nohup doesn't work in script started via ssh

nohup command 2>&1 & ?

nohup get it up after login, and the final & will put the process in background (without rattachments to tty).

do you use screen ?

Offline

 

#3 2012-11-12 19:03:21

rspitz
Member
Registered: 2012-10-13
Posts: 12

Re: nohup doesn't work in script started via ssh

The script I'm invoking via ssh from a remote machine contains, among others, these lines:

nohup cat $INTERFACE > ./heizung.dat 2>./heizung.err </dev/null &
echo $! > seriell_lesen.pid

Which is followed by some more.

The script executes just fine, but when the script exits, the nohuped "cat" command terminates.

When starting the script in a local ssh session, the nohuped "cat" command will survive the logoff.

Offline

 

#4 2012-11-12 23:45:54

rspitz
Member
Registered: 2012-10-13
Posts: 12

Re: nohup doesn't work in script started via ssh

Did a little more testing:

The same script when called remotely on my NSLU2 running Debian squeeze (Linux  2.6.32-5-ixp4xx) runs fine, the "cat" command will survive the end of the script and keep on running happily in the background.

I copied the "nohup" command from the Debian distribution over to the NAS to replace ffp's "nohup" in /ffp/bin, but that doesn't help. While the Debian nohup again does what's expected when called from within a shell running on the NAS, it will terminate when the script is called remotely.

I come to the conclusion that the fault must lie within the OS. Probably nothing I can do about it.

Offline

 

#5 2012-11-14 20:24:07

rsd76
Member
Registered: 2010-04-18
Posts: 47

Re: nohup doesn't work in script started via ssh

On other platforms I have had problems with using nohup. Sometimes it works, sometimes it doesn't.
My solution is letting the cron daemon start the processes.
I use the following commands to do this:

Code:

echo "/full/path/to/command argument1 argument2 > /path/to/stdout.txt 2>/path/to/stderr.txt" | at now

This give the cron a job to start. Then cron will start it immediately in the background. Not attached to the ssh process or even logon shell.
Not sure if this will work for you command.
And you normally aren't able to write the pid into a file.
You could try to write these commands in a script (still using an nohup).

Code:

#!/ffp/bin/sh

INTERFACE = /path/to/interface
nohup cat $INTERFACE > /path/to/heizung.dat 2>/path/to/heizung.err </dev/null &
echo $! > /path/to/seriell_lesen.pid

Just change the /path/to to the correct working directories. Add the execute bit to the script and run it like:

Code:

echo "/path/to/script.sh >/dev/null 2>&1" | at now

HTH


Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin & Hobbes)

Offline

 

#6 2012-11-15 23:33:28

rspitz
Member
Registered: 2012-10-13
Posts: 12

Re: nohup doesn't work in script started via ssh

I'm feeling terribly stupid yikes

Just looking at the first line of your script suggestion immediately showed me my mistake:

I had copied my script over from a RaspberryPi where /bin/sh is a symbolic link to a "real" shell (/bin/dash).
On my Medion NAS with FFP 0.7, /bin/sh is a symlink to busybox.

I only had to change the shebang path to /ffp/bin/bash (I prefer this over /ffp/bin/sh) and the nohup
is working perfectly when the script is invoked over ssh.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB