在/etc/rc。d/init。d/下编程脚本。
判断是否正常关机,和生成文件的脚本:touch-file。sh
#!/bin/shfile=/tmp/checkif [ -e ${file} ];thenecho "this is not normal shutdown" >>/var/log/checkmessageelseecho "this is normal shutdown and touch file" >>/var/log/checkmessagetouch ${file}fi
正常关机删除文件的脚本:rm-file。
sh #!/bin/shfile=/tmp/checkecho "this is normal shutdown and rm file" >>/var/log/checkmessagerm -rf ${file}
让脚本自动执行。 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。shln -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后面同名的空文件:。
全部