linux服务器:Linux环境下判断服务器是否正常关机

 系统启动时候生成个文件正常关机时候会删除这个文件网管员们则可以根据系统开机时有没有那个文件来判断是不是非正常关机减少网络管理过程中出现故障机率

  步骤:

  在/etc/rc.d/init.d/下编程脚本

  判断是否正常关机和生成文件脚本:touch-file.sh

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

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

  >>/var/log/checkmessage touch $ fi

  正常关机删除文件脚本:rm-file.sh

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

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

  让脚本自动执行

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

  注意:

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

  软连接两边名字不哪呢个相同个可以用绝对路径或是相对路径千万保证两边名字不

  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

  我系统没用到x-window,所以没有level5也就是不用在/etc/rc.d/rc5.d/下放脚本

  特别注意:

  K开头代表系统关闭时候执行S开头代表开机时候执行注意服务器脚本编写规范标准有K开通软链接并不定会在关机时候自动去执行这是为什么呢?执行K脚本时候会查询/var/lock/subsys/下是否有和K开头脚本同名空文件名如果没有就不去执行所以要按照服务器脚本编写规范标准启动时在/var/lock/subsys/先touch个和K01后面同名空文件:

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



Tags:  linux代理服务器 linux服务器配置 linuxftp服务器 linux服务器

延伸阅读

最新评论

发表评论