使用函数更加规范的开发rsync启动脚本
#!/bin/bash
#chkconfig:
#description: create by vincen . /etc/init.d/functions function usage(){
echo $"usage:$0 {start|stop|restart}"
exit
} function start(){
rsync --daemon
sleep
if [ `netstat -lntup|grep rsync|wc -l` -ge ];then
action "rsyncd is started." /bin/true
else
action "rsyncd is started." /bin/false
fi
} function stop(){
killall rsync
sleep
if [ `netstat -lntup|grep rsync|wc -l` -eq ];then
action "rsyncd is stopped." /bin/true
else
action "rsync is started." /bin/false
fi
} function main(){
if [ $# -ne ];then
usage
fi
if [ "$1" == "start" ];then
start
elif [ "$1" == "stop" ];then
stop
elif [ "$1" == "restart" ];then
stop
sleep
start
else
usage
fi
}
main $*
执行结果:
[root@rhel6 script]# /etc/init.d/rsyncd start
rsyncd is started. [ OK ]
[root@rhel6 script]# vim /etc/init.d/rsyncd
[root@rhel6 script]# /etc/init.d/rsyncd start
rsyncd is started. [ OK ]
[root@rhel6 script]# /etc/init.d/rsyncd stop
rsyncd is stopped. [ OK ]
[root@rhel6 script]# /etc/init.d/rsyncd restart
rsync: no process killed
rsyncd is stopped. [ OK ]
rsyncd is started. [ OK ]