1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > centos7 shell脚本开机自启动(亲测可用)

centos7 shell脚本开机自启动(亲测可用)

时间:2023-08-06 14:41:19

相关推荐

centos7 shell脚本开机自启动(亲测可用)

尝试了各种自启动,以下方式是唯一有效的

一. 编辑脚本

内容如下示例:

==================== startCrontab.sh ===================

#!/bin/sh

#chkconfig: 2345 90 10

#description:auto_run

cd /opt/swsk/shellCmd

python3 sh_krbInit.py > nohup.log 2>&1 &

ps -ef | grep pyCrontab.py | awk ‘{print $2}’ | xargs kill -9

python3 pyCrontab.py > nohup.log 2>&1 &

============================================

chkconfig参数说明:

上面的 2345 是启动级别,参考如下

****************** 对各个运行级的详细解释 ****************#

缺省的运行级,RHS用到的级别如下:

0:关机

1:单用户模式

2:无网络支持的多用户模式

3:有网络支持的多用户模式

4:保留,未使用

5:有网络支持有X-Window支持的多用户模式

6:重新引导系统,即重启

上面的 90 是启动优先级, 优先级范围是0-100,数字越大,优先级越低。

上面的 10 是停止优先级, 优先级范围是0-100,数字越大,优先级越低。

二. 相关定时任务的脚本加入自启动

将脚本拷贝到/etc/rc.d/init.d目录下

cp /opt/swsk/shellCmd/startCrontab.sh /etc/rc.d/init.d

增加脚本的可执行权限

chmod +x /etc/rc.d/init.d/startCrontab.sh

添加脚本到开机自动启动项目中

cd /etc/rc.d/init.d

chkconfig --add startCrontab.sh

chkconfig startCrontab.sh on

三. 重启测试

本文来自本人博客园

/icefoxhz/p/13677393.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。