Home> System Tutorial> LINUX> body text

Two ways to configure Linux to automatically start executing scripts at boot

WBOY
Release: 2024-06-25 16:49:27
Original
674 people have browsed it

Two ways to configure Linux to automatically start executing scripts at boot

Script qidong.sh to be started at startup

[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
Copy after login

Method 1: Modify /etc/rc.local

/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
Copy after login

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
Copy after login

Restart the system and check the results

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

This script has been started automatically after booting up

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
Copy after login

Add to chkconfig and start automatically at boot

[root@c69-01 ~]# chkconfig --add test
Copy after login
[root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:on 4:off 5:off 6:off
Copy after login

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
Copy after login

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
Copy after login

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')
Copy after login

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!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!