zoukankan      html  css  js  c++  java
  • 开发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 $*

    执行结果:

    [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  ]
  • 相关阅读:
    31-指针为什么区分类型
    30-多级指针的介绍
    29-指针的练习(包含指针的使用场景)
    28-指针的定义和初始化
    27-指针的概念
    26-字符串函数
    SringMVC Ajax
    SpringMVC返回数据到页面
    springmvc参数传递(二)
    springmvc参数传递(一)
  • 原文地址:https://www.cnblogs.com/vincenshen/p/6589697.html
Copyright © 2011-2022 走看看