[root@c69-01 scripts]# vim /server/scripts/qidong.sh [root@c69-01 scripts]# cat /server/scripts/qidong.sh #!/bin/bash /bin/echo $(/bin/date +%F_%T) >> /tmp/qidong.log
/etc/rc.local, this file is a link file
[root@c69-01 ~]# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 Feb 5 10:03 /etc/rc.local -> rc.d/rc.local
Modify the /etc/rc.local file
[root@c69-01 scripts]# tail -n 1 /etc/rc.local /bin/bash /server/scripts/qidong.sh >/dev/null 2>/dev/null
Restart the system and check the results
[root@c69-01 ~]# cat /tmp/qidong.log 2018-02-19_23:30:56
This script has been started automatically after booting up
Delete the configuration of method 1
[root@c69-01 ~]# vim /etc/init.d/test #!/bin/bash # chkconfig: 3 88 88 /bin/bash /server/scripts/qidong.sh >/dev/null 2>/dev/null [root@c69-01 ~]# chmod +x /etc/init.d/test
Add to chkconfig and start automatically at boot
[root@c69-01 ~]# chkconfig --add test
[root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:on 4:off 5:off 6:off
Restart the system and check the results
[root@c69-01 ~]# cat /tmp/qidong.log 2018-02-19_23:30:562018-02-19_23:59:10
Operation successful
Turn off and start up
[root@c69-01 ~]# chkconfig test off [root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Remove test from chkconfig management
[root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@c69-01 ~]# chkconfig --del test [root@c69-01 ~]# chkconfig --list test service test supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add test')
The above two methods of self-starting scripts at boot are for reference only. Readers can configure them according to their own circumstances!
Note: The system I am using is CentOS release 6.9 (Final)
The above is the detailed content of Two ways to configure Linux to automatically start executing scripts at boot. For more information, please follow other related articles on the PHP Chinese website!