Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does the Linux system run commands or scripts automatically at startup

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "Linux system how to automatically run commands or scripts at startup", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn how the Linux system automatically runs commands or scripts at startup "this article.

Method 1 using rc.local makes use of the rc.local file in / etc/ to execute scripts and commands at startup. We add a line to the file to execute the script so that the script is executed every time we start the system.

But first we need to add execution permissions to / etc/rc.local

$sudo chmod + x / etc/rc.local and then add the script you want to execute:

$sudo vi / etc/rc.local adds at the end of the file:

Sh / root/script.sh & then save the file and exit. Using the rc.local file to execute the command is the same, but be sure to fill in the full path to the command. If you want to know the full path of the command, you can run:

$which command for example:

$which shutter / usr/bin/shutter if it is CentOS, we modify the file / etc/rc.d/rc.local instead of / etc/rc.local. However, we also need to add executable permissions to the file first.

Note:-for scripts executed at startup, be sure to end with exit 0.

Method 2 uses Crontab, which is the easiest. We create a cron task that waits for 90 seconds after the system starts, and then executes commands and scripts.

To create a cron task, open the terminal and execute

$crontab-e and then enter the following content

@ reboot (sleep 90; sh\ location\ script.sh) where\ location\ script.sh is the address of the script to be executed.

The above is all the contents of the article "how to run commands or scripts automatically when the Linux system starts up". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report