[Linux] Continuously restart the specified number of times

1. Script code

First, you need to create a text to save test data such as "Number of restarts required" and "Current number of restarts". The script will automatically create it after detecting that there is no text at the specified location. First, specify the path where the test data saves the text. In the script Add a variable in , and then generate text under the specified path:

         Then get the data of the text every time it restarts, and observe how many times it has been restarted and how many times it needs to be restarted:

         After obtaining the data, start the restart operation:

         The restart command uses "shutdown", because the delay operation can be performed, and the source code is stored in the path:

Batch/cycle restarts for a specified number of times, and restarts will be performed automatically after booting , please download as needed.

 

2. Script placement

         After the script is written, place it in the /etc/profile.d path, and increase the script permission to 777

         The Profile.d file is a script belonging to the user under the folder that will be automatically executed when the user completes the login operation after booting up, so the following commands need to be executed to change the user ownership and group of the script to the current user:

         Finally, run the script twice (the first time to create the text to save the data, and the second time to enable restart), and then the continuous restart can be enabled.

Supongo que te gusta

Origin blog.csdn.net/qq_41884002/article/details/130359927
Recomendado
Clasificación