【发布时间】:2016-05-22 00:17:54
【问题描述】:
我正在学习在 linux(我正在使用 CentOS 6.7)和文件系统上使用 shell 脚本。现在我正在创建一个脚本,在系统启动或关闭时将消息写入文本文件。我在 /etc/init.d 中放置了以下内容:
#!/bin/sh
#
# This is a test that send messages to a log
LOGPATH=/home/user/documents
now=$(date +'%T')
start() {
echo "[$now] System startup" >> $LOGPATH/test.log
}
stop() {
echo "[$now] System shutdown" >> $LOGPATH/test.log
}
status() {
echo "[$now] Hi, you're checking status" >> $LOGPATH/test.log
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
status)
status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
然后我在 rc0 和 rc6 中创建了 K 个符号链接用于关机和重启,并在 rc5 中创建了 S 个符号链接(我的默认值)。
它在启动时工作,但在关机时没有。重启几次尝试不同的东西后,我只有“[time] System startup”,甚至给rc0中的脚本一个K01优先级。
为什么不工作在关机?也许重启时的终止信号不像我认为的那样有效,但我不确定。
【问题讨论】:
-
真的不是编程问题,是吗?
标签: linux shell centos symlink