This project is read-only.

issues executing a script and having it keep running after ssh session is closed

Oct 12, 2015 at 6:12 PM
I have a Linux script on a remote system that I need to execute via a SSH session and it needs to stay running after the session is closed. The script gathers data and stored in a local file for retrieval the next day. Something like:

echo "gathered data" >> daily.log

I can login via putty and execute the script fine using:
/sbin/myscript.sh &
or
nohup /sbin/myscript.sh &
But I cannot get it to work using ssh.net. My code looks like this:
ssh.Connect()
Dim startString = "/sbin/myscript.sh &"
Dim command = ssh.RunCommand(String.Format("{0}", startString))
Dim result = command.Result
ssh.Disconnect()
I've also prefaced the command with sh -c without success.

I have been able to get the file to start using
/sbin/myscript.sh >/dev/null 2>&1 &
but as this redirects stdout no data is getting written to my file.

After I try to start the script I run another routine to see if it did indeed start by looking at the results of a ps | grep myscript.sh

If I start the script manually I do get correct results from this routine so I know it is working.

Any thoughts on how to start a script remotely and keep it running after the session is closed?
Oct 13, 2015 at 12:34 PM
Solved

Script permissions were changed to root

Modified code to use ShellStream and su to root before executing
Marked as answer by master468 on 10/13/2015 at 4:34 AM