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?
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.
/etc/rc.local
file but when I reboot it doesn't work.. :/ My rc.local -> https://pastebin.com/bzCdJYEQ (ecoround is the user) – Jonathan Aug 10 '17 at 10:35./rc.local: line 1: !/bin/sh: No such file or directory
, this is probably why it won't work. Any idea why it's telling me this? – Jonathan Aug 10 '17 at 10:43