search
HomeSystem TutorialLINUXTwo ways to configure Linux to automatically start executing scripts at boot

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

Jun 25, 2024 pm 04:49 PM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

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

Script qidong.sh to be started at startup

[root@c69-01 scripts]<span class="hljs-comment"># vim /server/scripts/qidong.sh</span>

[root@c69-01 scripts]<span class="hljs-comment"># cat /server/scripts/qidong.sh</span>
<span class="hljs-meta">#!/bin/bash</span>
/bin/<span class="hljs-built_in">echo</span> $(/bin/date +%F_%T) >> /tmp/qidong.log

Method 1: Modify /etc/rc.local

/etc/rc.local, this file is a link file

[root@c69<span class="hljs-number">-01</span> ~]# ll /etc/rc.<span class="hljs-keyword">local</span> 
lrwxrwxrwx. <span class="hljs-number">1</span> root root <span class="hljs-number">13</span> Feb  <span class="hljs-number">5</span> <span class="hljs-number">10</span>:<span class="hljs-number">03</span> /etc/rc.<span class="hljs-keyword">local</span> -> rc.d/rc.<span class="hljs-keyword">local</span>

Modify the /etc/rc.local file

[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> scripts]<span class="hljs-comment"># tail -n 1 /etc/rc.local </span>
/bin/bash /server/scripts/qidong.sh ><span class="hljs-regexp">/dev/null</span> <span class="hljs-number">2</span>><span class="hljs-regexp">/dev/null</span>

Restart the system and check the results

<span class="hljs-selector-attr">[root@c69-01 ~]</span># <span class="hljs-selector-tag">cat</span> /<span class="hljs-selector-tag">tmp</span>/<span class="hljs-selector-tag">qidong</span><span class="hljs-selector-class">.log</span> 
<span class="hljs-selector-tag">2018-02-19_23</span><span class="hljs-selector-pseudo">:30</span><span class="hljs-selector-pseudo">:56</span>

This script has been started automatically after booting up

Method 2: chkconfig management

Delete the configuration of method 1

[root@c69-01 ~]<span class="hljs-comment"># vim /etc/init.d/test </span>
<span class="hljs-meta">#!/bin/bash</span>
<span class="hljs-comment"># chkconfig: 3 88 88</span>
/bin/bash /server/scripts/qidong.sh >/dev/null 2>/dev/null

[root@c69-01 ~]<span class="hljs-comment"># chmod +x /etc/init.d/test</span>

Add to chkconfig and start automatically at boot

[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --add test</span>
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span>
test           	<span class="hljs-number">0</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">1</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">2</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">3</span><span class="hljs-symbol">:on</span>	<span class="hljs-number">4</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">5</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">6</span><span class="hljs-symbol">:off</span>

Restart the system and check the results

<span class="hljs-selector-attr">[root@c69-01 ~]</span># <span class="hljs-selector-tag">cat</span> /<span class="hljs-selector-tag">tmp</span>/<span class="hljs-selector-tag">qidong</span><span class="hljs-selector-class">.log</span> 
<span class="hljs-selector-tag">2018-02-19_23</span><span class="hljs-selector-pseudo">:30</span><span class="hljs-selector-pseudo">:56</span>
2018-02-19_23:59:10

Operation successful

Turn off and start up

[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig test off</span>
[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span>
test           	<span class="hljs-number">0</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">1</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">2</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">3</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">4</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">5</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">6</span><span class="hljs-symbol">:off</span>

Remove test from chkconfig management

[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span>
test           	<span class="hljs-number">0</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">1</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">2</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">3</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">4</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">5</span><span class="hljs-symbol">:off</span>	<span class="hljs-number">6</span><span class="hljs-symbol">:off</span>

[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --del test</span>

[root<span class="hljs-variable">@c69</span>-<span class="hljs-number">01</span> ~]<span class="hljs-comment"># chkconfig --list test</span>
service test supports chkconfig, but is <span class="hljs-keyword">not</span> referenced <span class="hljs-keyword">in</span> any runlevel (run <span class="hljs-string">'chkconfig --add test'</span>)

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!

Statement
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
How does performance differ between Linux and Windows for various tasks?How does performance differ between Linux and Windows for various tasks?May 14, 2025 am 12:03 AM

Linux performs well in servers and development environments, while Windows performs better in desktop and gaming. 1) Linux's file system performs well when dealing with large numbers of small files. 2) Linux performs excellently in high concurrency and high throughput network scenarios. 3) Linux memory management has more advantages in server environments. 4) Linux is efficient when executing command line and script tasks, while Windows performs better on graphical interfaces and multimedia applications.

How to Create GUI Applications In Linux Using PyGObjectHow to Create GUI Applications In Linux Using PyGObjectMay 13, 2025 am 11:09 AM

Creating graphical user interface (GUI) applications is a fantastic way to bring your ideas to life and make your programs more user-friendly. PyGObject is a Python library that allows developers to create GUI applications on Linux desktops using the

How to Install LAMP Stack with PhpMyAdmin in Arch LinuxHow to Install LAMP Stack with PhpMyAdmin in Arch LinuxMay 13, 2025 am 11:01 AM

Arch Linux provides a flexible cutting-edge system environment and is a powerfully suited solution for developing web applications on small non-critical systems because is a completely open source and provides the latest up-to-date releases on kernel

How to Install LEMP (Nginx, PHP, MariaDB) on Arch LinuxHow to Install LEMP (Nginx, PHP, MariaDB) on Arch LinuxMay 13, 2025 am 10:43 AM

Due to its Rolling Release model which embraces cutting-edge software Arch Linux was not designed and developed to run as a server to provide reliable network services because it requires extra time for maintenance, constant upgrades, and sensible fi

12 Must-Have Linux Console [Terminal] File Managers12 Must-Have Linux Console [Terminal] File ManagersMay 13, 2025 am 10:14 AM

Linux console file managers can be very helpful in day-to-day tasks, when managing files on a local machine, or when connected to a remote one. The visual console representation of the directory helps us quickly perform file/folder operations and sav

qBittorrent: A Powerful Open-Source BitTorrent ClientqBittorrent: A Powerful Open-Source BitTorrent ClientMay 13, 2025 am 10:12 AM

qBittorrent is a popular open-source BitTorrent client that allows users to download and share files over the internet. The latest version, qBittorrent 5.0, was released recently and comes packed with new features and improvements. This article will

Setup Nginx Virtual Hosts, phpMyAdmin, and SSL on Arch LinuxSetup Nginx Virtual Hosts, phpMyAdmin, and SSL on Arch LinuxMay 13, 2025 am 10:03 AM

The previous Arch Linux LEMP article just covered basic stuff, from installing network services (Nginx, PHP, MySQL, and PhpMyAdmin) and configuring minimal security required for MySQL server and PhpMyadmin. This topic is strictly related to the forme

Zenity: Building GTK  Dialogs in Shell ScriptsZenity: Building GTK Dialogs in Shell ScriptsMay 13, 2025 am 09:38 AM

Zenity is a tool that allows you to create graphical dialog boxes in Linux using the command line. It uses GTK , a toolkit for creating graphical user interfaces (GUIs), making it easy to add visual elements to your scripts. Zenity can be extremely u

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor