首页 > 系统服务 > 详细

七、Shell脚本高级编程实战第七部

时间:2019-10-01 19:53:53      阅读:110      评论:0      收藏:0      [点我收藏+]

一、写网络服务的系统启动脚本

   利用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
}
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

 测试:

 技术分享图片

 

七、Shell脚本高级编程实战第七部

原文:https://www.cnblogs.com/dangjingwei/p/11615808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!