#! /bin/bash

if [ $# -ne 1 ];then echo " usage:$0 {start|stop|restart}" exit 5 fi

if [ "$1" = "start" ];then rsync --daemon sleep 1 if [ netstat -tnlup | grep rsync | wc -l -ge 1 ];then echo "rsync server is running." exit 0 fi elif [ "$1" = "stop" ];then killall rysnc &> /dev/null sleep 1 if [ netstat -tnlup | grep rsync | wc -l -eq 0 ];then echo "rsync is stopped." exit 0 fi elif [ "$1" = "restart" ];then killall rsync &> /de/null sleep 1 killpro=netstat -tlnup | grep rsync | wc -l rsync --daemon sleep 1 startpro=netstat -tnlup | grep rsync | wc -l if [ $killpro -eq 0 -a $startpro -ge 1 ];then echo "rsyncd is restart" exit 0 fi

else echo $"usage:$0 {start|stop|restart}" exit 1 fi