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

Implementation of the function of executing the specified script when Linux shuts down

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. Specific ideas for executing a script when shutting down

(1) create the script file_name to be executed during shutdown under the folder / etc/init.d/

(2) create a link file K07file_name for the script file under the folder / etc/rc0.d/ and / etc/rc6.d/, respectively:

Sudo ln-s / etc/init.d/file_name / etc/rc0.d/K07file_namesudo ln-s / etc/init.d/file_name / etc/rc6.d/K07file_name

(3) generate a file with the same name as file_name under the folder / var/lock/subsys/

Sudo mkdir-p / var/lock/subsys/sudo touch / var/lock/subsys/file_name

Note: the keyword K07 only needs to be added in the folders / etc/rc0.d/ and / etc/rc6.d/, in / etc/init.d/ and

/ var/lock/subsys/ does not need to be added.

two。 Example-execute script snaking616 when Linux shuts down

The script snaking616 contains the following:

#! / bin/bash cd / etc/init.d echo "admin" | sudo-S touch eth_set_100 echo "admin" | sudo-S chmod 777 eth_set_100 echo "#! / bin/bash echo" admin "| sudo-S ethtool-s eth2 autoneg off speed 100 duplex full" > eth_set_100

When the system shuts down, the script automatically generates the script file eth_set_100 under the folder / etc/init.d and writes the following to the file:

#! / bin/bash echo "admin" | sudo-S ethtool-s eth2 autoneg off speed 100duplex full

The specific implementation methods are as follows:

(1) Open the terminal to create a script file snaking616

Sudo touch / etc/init.d/snaking616sudo chmod 777 / etc/init.d/snaking616sudo gedit / etc/init.d/snaking616

Fill in the following code:

#! / bin/bash cd / etc/init.d echo "admin" | sudo-S touch eth_set_100 echo "admin" | sudo-S chmod 777 eth_set_100 echo "#! / bin/bash echo" admin "| sudo-S ethtool-s eth2 autoneg off speed 100 duplex full" > eth_set_100

(2) create a connection file

Sudo ln-s / etc/init.d/snaking616 / etc/rc0.d/K07snaking616sudo ln-s / etc/init.d/snaking616 / etc/rc6.d/K07snaking616

(3) generate a file with the same name as snaking616 under the folder / var/lock/subsys/

Sudo mkdir-p / var/lock/subsys/sudo touch / var/lock/subsys/snaking616

When the system shuts down, under the folder / etc/init.d, the script file eth_set_100 is automatically generated.

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

Servers

Wechat

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

12
Report