CentOS在启动时 将任意脚本 放到screen里 执行的方法,亲测有效

第一步
给 /etc/rc.local 执行权限

chmod o+x /etc/rc.local

第二步
编辑 脚本文件,以下面的为例说明
vi /root/start.sh
里面填入需要的脚本命令

#!/bin/bash

screen_name="my_screen"
screen -dmS $screen_name

cmd="/.pyenv/versions/3.9.7/bin/python3 /root/json.py";   #要执行的脚本

screen -x -S $screen_name -p 0 -X stuff "$cmd"
screen -x -S $screen_name -p 0 -X stuff $'\n'


保存退出后,把 /root/start.sh 增加执行权限

chmod o+x /root/start.sh

第三步
最后编辑 /etc/rc.local 把 /root/start.sh 放到里面去 ,就是在exit 0 这行代码前面

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

/root/start.sh


exit 0


发表评论

您的电子邮箱地址不会被公开。

− 1 = 1