码迷,mamicode.com
首页 > 系统相关 > 详细

利用shell开发rsync服务启动脚本

时间:2018-02-05 10:36:52      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:opp   /etc   net   kconfig   shu   shadow   init.d   water   config   

利用shell函数开发rsync服务启动脚本,之前的不够专业

#!/bin/bash

#chkconfig: 2345  20 80                       #这两行加入kconfig
#description: Saves and restores system entropy  pool
source /etc/init.d/functions    #调用标准的函数库
aa() {
  echo "plz one canshu"
  exit 5
}
bb() {
if [ $1 == "start" ]; then
  rsync --daemon
  if [ "`netstat -tlnup | grep rsync | wc -l`" -gt 0 ]; then
    action "starting rsgnc..." /bin/true     #注意这里
  else
    action "stoped rsync... "  /bin/flase
  exit 6
fi

elif [ $1 == "stop" ]; then
 # kill  "`ps -ef | grep rsync | grep -v grep | awk -F ' ' '{print $2}'`"
  killall rsync
  sleep 2
  if  [ "`netstat -tlnup | grep rsync | wc -l`" -eq 0 ]
    then  action "rsync is stopped" /bin/true
  else
     action "no stop" /bin/flase
  exit 3
  fi
elif [ $1 == "restart" ]; then
  #kill "`ps -ef | grep rsync | grep -v grep | awk -F ' ' '{print $2}'`"
  killall rsync
  sleep 2
  rsync --daemon
  if [ "`netstat -tlnup | grep rsync | wc -l`" -gt 0  ]
    then  action "rsync is starting"  /bin/true
  else
    action "rsync is stopped"  /bin/flase

    exit 2
  fi
else
  echo "plz currt int"
fi
}

main() {
if [ $# -ne 1 ]
  then
    aa
fi
bb $1
}

main $*

技术分享图片

利用shell开发rsync服务启动脚本

标签:opp   /etc   net   kconfig   shu   shadow   init.d   water   config   

原文地址:http://blog.51cto.com/11726212/2068818

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!