1

How can I make a script run on startup as root and also creating a screen for the script?

I think I could just add

screen -S name

to the top of the script to achieve the screen stuff, but I'm not sure.

Is this all possible to do in crontab?

Jonathan
  • 317

1 Answers1

2

We use (in a perl script that is started in /etc/rc.local with

su {username} -c '/usr/local/bin/schermen start'

The script has a "start","stop" and "restart" options.

):

screen -d -m -S {screen_name} {$program_to_start}

The man page has a notice om using -d -m:

-m   causes  screen  to  ignore the $STY environment variable. 
With "screen -m" creation of a new session is enforced, 
regardless whether screen is called from within another screen session 
or not. This flag has a special meaning in connection with the `-d' option:

-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.

Extra:

-S sessionname When creating a new session, this option can be used 
to specify a meaningful name for the session. 
This name identifies  the  session  for  "screen -list" 
and "screen -r" actions. It substitutes the default [tty.host] suffix.
Rinzwind
  • 309,379