企业Shell面试题15:开发Rsync服务启动脚本案例
[root@oldboy 10-31]# cat backup_rsync.sh #!/bin/bash ############################################################## # File Name: backup_rsync.sh # Version: V1.0 # Author: HU JIN SHENG # Organization: www.oldboyedu.com # Created Time : 2017-11-01 02:41:11 # Description: ############################################################## . /etc/init.d/functions case "$1" in start) echo "rsync is starting" rsync --daemon sleep 2 myport=`netstat -luntp|grep 873|wc -l` if [ $myport -eq 2 ] then action "rsync start" /bin/true else action "rsync start" /bin/false fi ;; stop) echo "rsync is stoping" myport=`netstat -luntp|grep 873|wc -l` if [ $myport -eq 2 ] then killall rsync &>/dev/null sleep 2 killall rsync &>/dev/null sleep 1 fi if [ $myport -ne 2 ] then action "rsync stop" /bin/true else action "rsync stop" /bin/false fi ;; restart) myport=`netstat -lnt|grep 873|wc -l` if [ $myport -eq 0 ] then rsync --daemon sleep 2 rsync --daemon sleep if [ $myport -eq 2 ] then action "restart rsync" /bin/true else action "restart rsync" /bin/false exit fi else killall rsync &>/dev/null sleep 2 killall rsync &>/dev/null sleep 1 if [ $myport -eq 2 ] then action "rsync restart" /bin/true else action "rsync restart" /bin/false fi fi status) myport=`netstat -lnt|grep 873|wc -l` if [ $myport -eq 2 ] then echo "rsync is running" else echo "rsync is stoped" fi ;; *) echo $ "Usage: $0 {start|stop|status|restart} " ;; esac (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |