开发rsync启动脚本2

Posted Vincen_shen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发rsync启动脚本2相关的知识,希望对你有一定的参考价值。

使用函数更加规范的开发rsync启动脚本

#!/bin/bash
#chkconfig: 2345 20  80
#description: create by vincen

. /etc/init.d/functions

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

function start(){
        rsync --daemon
        sleep 1
        if [ `netstat -lntup|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
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -eq 0 ];then
                action "rsyncd is stopped." /bin/true
        else
                action "rsync is started." /bin/false
        fi
}

function main(){
        if [ $# -ne 1 ];then
                usage
        fi
        if [ "$1" == "start" ];then
                start
        elif [ "$1" == "stop" ];then
                stop
        elif [ "$1" == "restart" ];then
                stop
                sleep 1
                start
        else
                usage
        fi
}
main $*

执行结果:

[[email protected] script]# /etc/init.d/rsyncd start
rsyncd is started.                                         [  OK  ]
[[email protected] script]# vim /etc/init.d/rsyncd  
[[email protected] script]# /etc/init.d/rsyncd start
rsyncd is started.                                         [  OK  ]
[[email protected] script]# /etc/init.d/rsyncd stop
rsyncd is stopped.                                         [  OK  ]  
[[email protected] script]# /etc/init.d/rsyncd restart
rsync: no process killed
rsyncd is stopped.                                         [  OK  ]
rsyncd is started.                                         [  OK  ]

 

以上是关于开发rsync启动脚本2的主要内容,如果未能解决你的问题,请参考以下文章

开发rsync服务的启动脚本

利用shell开发rsync服务启动脚本

15:开发Rsync服务启动脚本案例

rsync启动脚本编写

rsync启动脚本

rsync启动停止脚本