如何让脚本在启动时以 root 身份运行并为该脚本创建屏幕?
我想我可以补充一下
screen -S name
到脚本的顶部来实现屏幕内容,但我不确定。
这一切都可以在 crontab 中完成吗?
答案1
我们使用(在 /etc/rc.local 中启动的 perl 脚本
su {username} -c '/usr/local/bin/schermen start'
该脚本有“开始”、“停止”和“重新启动”选项。
):
screen -d -m -S {screen_name} {$program_to_start}
手册页中有关于使用的通知-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.
额外的:
-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.