
有时我们需要将shell脚本作为开机自启动服务,这样能避免出现问题后重新开机还需要再挨个启动服务
脚本内容如下
#!/bin/bash #chkconfig: 2345 90 10 #description:auto_run echo "success!" >> /root/test.txt
#chkconfig: 2345 90 10
#description:auto_run
以上两行标注蓝色的代码必须要加上,否则在执行"chkconfig --add xxx.sh"时会报如下错误:
service test.sh does not support chkconfig
chkconfig参数说明:
编写完脚本后,将脚本移动到/etc/rc.d/init.d目录
mv /root/test.sh /etc/rc.d/init.d
赋予脚本执行权
chmod +x /etc/rc.d/init.d/test.sh
添加脚本到开机自启动项目中
chkconfig --add test.sh chkconfig test.sh on
配置好这些后就可以了,可以reboot一下测试结果,我重启两次后结果如下:
cat test.txt success! success!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)