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

Oct 12, 2015 at 5: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/ &
nohup /sbin/ &
But I cannot get it to work using My code looks like this:
Dim startString = "/sbin/ &"
Dim command = ssh.RunCommand(String.Format("{0}", startString))
Dim result = command.Result
I've also prefaced the command with sh -c without success.

I have been able to get the file to start using
/sbin/ >/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

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 11:34 AM

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