首页 > 其他 > 详细

开发rsync启动脚本2

时间:2017-03-20 16:33:29      阅读:131      评论:0      收藏:0      [点我收藏+]

使用函数更加规范的开发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 $*

执行结果:

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

 

开发rsync启动脚本2

原文:http://www.cnblogs.com/vincenshen/p/6589697.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!