Implementation of the function of executing the specified script when Linux shuts down
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.