[root@oldboy 10-31]# cat backup_rsync.sh@H_301_1@
#!/bin/bash@H_301_1@
##############################################################@H_301_1@
# File Name: backup_rsync.sh@H_301_1@
# Version: V1.0@H_301_1@
# Author: HU JIN SHENG@H_301_1@
# Organization: www.oldboyedu.com@H_301_1@
# Created Time : 2017-11-01 02:41:11@H_301_1@
# Description:@H_301_1@
##############################################################@H_301_1@
. /etc/init.d/functions@H_301_1@
case "$1" in@H_301_1@
start)@H_301_1@
echo "rsync is starting"@H_301_1@
rsync --daemon@H_301_1@
sleep 2@H_301_1@
myport=`netstat -luntp|grep 873|wc -l`@H_301_1@
if [ $myport -eq 2 ]@H_301_1@
then@H_301_1@
action "rsync start" /bin/true@H_301_1@
else@H_301_1@
action "rsync start" /bin/false@H_301_1@
fi@H_301_1@
;;@H_301_1@
stop)@H_301_1@
echo "rsync is stoping"@H_301_1@
myport=`netstat -luntp|grep 873|wc -l`@H_301_1@
if [ $myport -eq 2 ]@H_301_1@
then@H_301_1@
killall rsync &>/dev/null@H_301_1@
sleep 2@H_301_1@
killall rsync &>/dev/null@H_301_1@
sleep 1@H_301_1@
fi@H_301_1@
if [ $myport -ne 2 ]@H_301_1@
then@H_301_1@
action "rsync stop" /bin/true@H_301_1@
else@H_301_1@
action "rsync stop" /bin/false@H_301_1@
fi@H_301_1@
;;@H_301_1@
restart)@H_301_1@
myport=`netstat -lnt|grep 873|wc -l`@H_301_1@
if [ $myport -eq 0 ]@H_301_1@
then@H_301_1@
rsync --daemon@H_301_1@
sleep 2@H_301_1@
rsync --daemon@H_301_1@
sleep@H_301_1@
if [ $myport -eq 2 ]@H_301_1@
then@H_301_1@
action "restart rsync" /bin/true@H_301_1@
else@H_301_1@
action "restart rsync" /bin/false@H_301_1@
exit@H_301_1@
fi@H_301_1@
else@H_301_1@
killall rsync &>/dev/null@H_301_1@
sleep 2@H_301_1@
killall rsync &>/dev/null@H_301_1@
sleep 1@H_301_1@
if [ $myport -eq 2 ]@H_301_1@
then@H_301_1@
action "rsync restart" /bin/true@H_301_1@
else@H_301_1@
action "rsync restart" /bin/false@H_301_1@
fi@H_301_1@
fi@H_301_1@
status)@H_301_1@
myport=`netstat -lnt|grep 873|wc -l`@H_301_1@
if [ $myport -eq 2 ]@H_301_1@
then@H_301_1@
echo "rsync is running"@H_301_1@
else@H_301_1@
echo "rsync is stoped"@H_301_1@
fi@H_301_1@
;;@H_301_1@
*)@H_301_1@
echo $ "Usage: $0 {start|stop|status|restart} "@H_301_1@
;;@H_301_1@
esac@H_301_1@