为了开机时以普通用户自动启动测试程序,并且以后每天测试一遍,再编写以下两个脚本。
第一个脚本:
# /home/mishuang/bin/start-stop
PID_FILE=/tmp/monitor.pid
case "$1" in
start)
if [ -f $PID_FILE ]
then
echo "monitor already started!"
exit 1
fi
echo $$ > $PID_FILE
while true
do
seconds=$((24*60*60))
sleep $seconds
/home/mishuang/bin/monitor
done
;;
stop)
if [ -f $PID_FILE ]
then
pid=`cat $PID_FILE`
kill -9 $pid
echo "remove pid file"
rm -f $PID_FILE
else
echo "monitor already terminated!"
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
printf "Usage: $0 {start|stop|restart}\n" >&2
exit 1
;;
esac
exit 0
第二个脚本:
# /etc/init.d/monitor
case "$1" in
start)
su - mishuang /home/mishuang/bin/start-stop start &
;;
stop)
su - mishuang /home/mishuang/bin/start-stop stop
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
printf "Usage: $0 {start|stop|restart}\n" >&2
exit 1
;;
esac
exit 0
最后chkconfig monitor on
阅读(1641) | 评论(0) | 转发(0) |