Run "screen -S name ./script" command on @reboot using crontab

Ahmed Hamdy picture Ahmed Hamdy · Jul 3, 2013 · Viewed 8.3k times · Source

I've tried adding this to my crontab:

@reboot /root/startup

The "startup" file:

#!/bin/sh

svnserve -d -r /root/svnrepos/mainres
svnserve -d -r /root/svnrepos/mapres --listen-port=3691
screen -S mta ./mtaserver/mta-server > log1
screen -S mapmta ./mapserver/mta-server > log2

exit 0

Now svnserve commands run fine. The problem is with the screen command.

log1 and log2 files have the same content which is: Must be connected to a terminal.

What I'm trying to do is start the 2 executables on startup, and then later have a way to access them.

Is there a way to do this?

Answer

AMADANON Inc. picture AMADANON Inc. · Jul 3, 2013

You want to add the following options to the 'screen' commands (e.g. before -S): -d -m From the manpage:

   -d -m   Start screen in "detached" mode. This creates a new session but
           doesn't  attach  to  it.  This  is  useful  for  system startup
           scripts.