Determine whether the server is shut down normally under Linux environment

  

A file is generated when the system is started, and will be deleted when the system is shut down normally. The network administrators can judge whether the abnormal shutdown is based on whether there is a file at the time of booting the system, and reduce the probability of failure in the network management process.

Steps:

Program the script in /etc/rc.d/init.d/.

To determine if the shutdown is normal, and the script that generates the file: touch-file.sh

#!/bin/sh file=/tmp/check if [ -e $ ];then echo " ;this is not normal shutdown"

>>/var/log/checkmessage else echo "this is normal shutdown and touch file"

>>/var/log/Checkmessage touch $ fi

Script to delete files normally: rm-file.sh

#!/bin/sh file=/tmp/check echo "this is normal shutdown and rm file" ;

>>/var/log/checkmessage rm -rf $

Let the script execute automatically.

ln -s /etc/rc.d/rc0.d/K01rm-file /etc/rc.d/init.d/rm-file.sh

Note:

#ll /etc/rc.d/rc0.d/

The names of the two sides of the soft connection are not the same. The latter one can use absolute or relative paths. Different.

ln -s /etc/rc.d/rc6.d/K01rm-file /etc/rc.d/init.d/rm-file.sh ln -s

/etc /rc.d/rc3.d/S01touch-file /etc/rc.d/init.d/touch-file.sh

My system doesn't use x-window, so there is no level5, which is There is no need to drop the script in /etc/rc.d/rc5.d/.

Special Note:

When K starts, the system is executed when it is closed, and the beginning of S is executed when it is turned on. Pay attention to the specification of server scripting, because the soft link opened by K does not necessarily execute automatically when it is shut down. Why is this? When executing K script, it will query whether there is K with /var/lock/subsys/. The empty file name of the same name of the opening script, if not, will not be executed, so according to the specification of the server script, when starting, touch an empty file with the same name behind K01 in /var/lock/subsys/:

#/var/lock/subsys #touch fm-file

Copyright © Windows knowledge All Rights Reserved