shell脚本之rsync自动化脚本

要求:写一个脚本可以直接用脚本控制rsync服务的开启,停止和重启

#!/bin/bash

. /etc/init.d/functions

function usage() {
    echo $"usage:$0 {start|stop|restart}"
    exit 1
}

function start() {
    rsync --daemon
    sleep 1
    if [ `netstat -antlpe | grep rsync | wc -l` -ge 1 ];then
        action "rsyncd is started." /bin/true
    else
        action "rsyncd is started." /bin/false
    fi
}

function stop() {
    killall rsync &> /dev/null
    sleep 1
    if [ `netstat -antlpe | grep rsync | wc -l` -eq 0 ];then
        action "rsyncd is stoped." /bin/true
    else
        action "rsyncd is stoped." /bin/false
    fi
}

function main() {
    if [ $# -ne 1 ];then
        usage $0
    fi
    case $1 in
        start)
        start
	;;
	stop)
	stop
	;;
	restart)
	stop
	start
	;;
	*)
	usage $0
	;;
    esac
}

main $*

运行一下

ok~

猜你喜欢

转载自blog.csdn.net/weixin_40543283/article/details/85725020
今日推荐