利用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 $*
原文地址:http://blog.51cto.com/11726212/2068818
时间: 2024-10-18 02:11:48