1

I would like to shoot a command to server to be run say forever! under "screen session" using ssh.

so I am using something like

ssh -t root@server screen -S myinf "python infinit1.py &"

where infinit1.py is the script. The problem the "python infinit1.py" doesn't go in a background and neither a screen called "myinf" is created.

I appreciate your hints.

Rik Schneider
  • 2,479
  • 14
  • 19
user702846
  • 133
  • 1
  • 7

3 Answers3

1

do this

 ssh -t root@server "nohup bash -c '( ( /usr/bin/python infinit1.py &> /dev/null ) & )'"

this is because the tty that opened need to close and thus cannot keep the command running. to see the output, change /dev/null to an actual file name.

i have not tried to use remote screen so I omitted that. you may be able to get it to work but maybe the syntax is off a little bit.

johnshen64
  • 5,865
  • 24
  • 17
1

This is because screen as invoked by you requires a pty to function. You will need to start screen in detached mode:

ssh root@server screen -d -m -S myinf python infinit1.py
Dennis Kaarsemaker
  • 19,277
  • 2
  • 44
  • 70
0

You don't need the quotes or the ampersand. Use the -d -m options to start screen in a detached mode instead. Take a look at the man page for more infomation.

A working example command line is:

ssh $host screen -S myinf -d -m tail -F /var/log/dmesg
Rik Schneider
  • 2,479
  • 14
  • 19
  • sudo for what !? I don't have sudo access ! – user702846 Jul 16 '13 at 23:01
  • It isn't important for the discussion. I used sudo to read a log file since I don't have infinit1.py on my test host. The important part is that everything after the options is considered a command line to run inside the screen session. – Rik Schneider Jul 16 '13 at 23:25