七Shell脚本高级编程实战第七部
Posted dangjingwei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了七Shell脚本高级编程实战第七部相关的知识,希望对你有一定的参考价值。
一、写网络服务的系统启动脚本
利用case语句开发类似系统启动rsync服务的脚本
代码:
#!/bin/sah
. /etc/init.d/functions
pidfile="/var/run/rsyncd.pid"
start_rsync()
if [ -f "$pidfile" ]
then
echo "rsync is running"
else
rsync --daemon
action "rsync is started" /bin/true
fi
stop_rsync()
if [ -f "$pidfile" -a -n "$pidfile" ]
then
kill -USR2 `cat $pidfile`
rm -f $pidfile
action "rsync is stopped" /bin/true
else
action "rsync have already been rstopped" /bin/false
fi
. /etc/init.d/functions
pidfile="/var/run/rsyncd.pid"
start_rsync()
if [ -f "$pidfile" ]
then
echo "rsync is running"
else
rsync --daemon
action "rsync is started" /bin/true
fi
stop_rsync()
if [ -f "$pidfile" -a -n "$pidfile" ]
then
kill -USR2 `cat $pidfile`
rm -f $pidfile
action "rsync is stopped" /bin/true
else
action "rsync have already been rstopped" /bin/false
fi
case "$1" in
start)
start_rsync
RETVAL=$?
;;
stop)
stop_rsync
RETVAL=$?
;;
restart)
stop_rsync
sleep 10
start_rsync
RETVAL=$?
;;
*)
echo "USAGE: $0 start|stop|restart"
exit 1
;;
esac
exit $RETVAL
start)
start_rsync
RETVAL=$?
;;
stop)
stop_rsync
RETVAL=$?
;;
restart)
stop_rsync
sleep 10
start_rsync
RETVAL=$?
;;
*)
echo "USAGE: $0 start|stop|restart"
exit 1
;;
esac
exit $RETVAL
测试:
以上是关于七Shell脚本高级编程实战第七部的主要内容,如果未能解决你的问题,请参考以下文章