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


    [root@m01 ~]# rsn_count="ps -ef|grep 'rsync --d[a]emon'|wc -l"
    [root@m01 ~]# echo ${rsn_count}
    ps -ef|grep 'rsync --d[a]emon'|wc -l
    [root@m01 ~]# eval ${rsn_count}
    1
    
    变量多次获取值得思路:
    
    定义变量
    
    每次执行的时候就执行   eval ${rsn_count}
    每次获取的都是新值,
    
    第二种思路:
    
    一开始
     rsn_count=$(ps -ef|grep 'rsync --d[a]emon'|wc -l)
    
    获取变量
    然后再次获取的时候
    
    执行命令ps -ef|grep 'rsync --d[a]emon'|wc -l 获取
    [root@m01 20171207]# cat ryn_srv.sh 
    
    #!/bin/bash
    rsn_file="/usr/bin/rsync"
    # 判断启动的进程数
    
    [ -e /etc/init.d/functions ] && source /etc/init.d/functions || echo "/etc/init.d/functions 不存在"
    [ -e ${rsn_file} ] || {
        echo "${rsn_file} 服务不存在"
        exit 11
    }
    args1=$1
    
    function start() {
        if [ $(ps -ef|grep "rsync --d[a]emon"|wc -l) -gt 0 ]
        then
            echo "rsync 已经启动"
        
        else 
    
            ${rsn_file} --daemon
            sleep 1
            [ $(ps -ef|grep "rsync --d[a]emon"|wc -l) -gt 0 ] && action "rsync 启动成功"  /bin/true || echo "启动失败"
    
        fi
    
    }
    
    function stop() {
    
        if [ $(ps -ef|grep "rsync --d[a]emon"|wc -l) -gt 0 ]
            then
                    killall rsync
                    killall rsync &>/dev/null
            sleep 1        
            [ $(ps -ef|grep "rsync --d[a]emon"|wc -l) -lt 1 ] && action "rsync  关闭成功"  /bin/true || echo "关闭失败"
    
            
            else 
    
                    echo "rsync 已经关闭"
    
    
            fi
    
        
    }
    
    function restart() {
        stop
        sleep 2
        start
    }
    
    case $args1 in
         start)
         start
         ;;
         stop)
         
         stop
         ;;
         
         restart)
         
         restart
         ;;
         
         *)
         echo "Usage  {start|stop|restart}"
         ;;
         
    esac
  • 相关阅读:
    软件加载前显示加载中画面
    datatable用法
    arcsde安装
    dev gridcontrol (一)绑定值
    dev常用
    lookupedit用法(combox功能)
    关于NetBox2.8端口问题
    asp.net中,登录互斥的相关代码(不包含中途退出的处理)
    我老婆其人其事(一)
    判断文件是否为UTF8编码(以前收集的)
  • 原文地址:https://www.cnblogs.com/gaoyuechen/p/7999680.html
Copyright © 2020-2023  润新知