There are two ways to configure Linux to execute scripts automatically after booting

Script qidong.sh to be started at boot

[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

Method 1: Modify /etc/rc.local

/etc/rc.local, which is the 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 to see the results

[root@c69-01 ~]# cat /tmp/qidong.log 
2018-02-19_23:30:56

The script starts automatically after booting

Method 2: chkconfig management

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, 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 to see the results

[root@c69-01 ~]# cat /tmp/qidong.log 
2018-02-19_23:30:56
2018-02-19_23:59:10

Successful operation

turn off startup 

[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 starting the script at startup are for reference only. Readers can configure it according to their own situation!

 

Note: The system I use is CentOS release 6.9 (Final)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324439938&siteId=291194637