开发rsync启动脚本

rsync

rsync是类unix系统下的数据镜像备份工具——remote sync。一款快速增量备份工具 Remote Sync,远程同步 支持本地复制,或者与其他SSH、rsync主机同步。
 

启动/停止命令:

rsync --daemon
pkillall rsync
 

rsync脚本

#!/bin/bash

if [ $# -ne 1 ];then
        echo $"usage:$0 {start|stop|restart}"
        exit 1
fi

if [ "$1" = "start" ];then
        rsync --daemon
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -ge 1 ];then
                echo "rsyncd is started."
                exit 0
        fi
elif [ "$1" = "stop" ];then
        killall rsync
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -eq 0 ];then
                echo "rsyncd is stopped."
                exit 0
        fi
elif [ "$1" == "restart" ];then
        killall rsync &>/dev/null
        sleep 1
        killpro=`netstat -lntup|grep rsync|wc -l`
        rsync --daemon
        sleep 1
        startpro=`netstat -lntup|grep rsync|wc -l`
        if [ $killpro -eq 0 -a $startpro -ge 1 ];then
                echo "rsyncd is restarted."
                exit 0
        fi
else
        echo $"usage:$0 {start|stop|restart}"
        exit 1
fi

 

添加到chkconfig

需要在脚本开头添加以下两行内容: 2345启动基本, 20启动顺序,80停止顺序

#chkconfig: 2345 20  80
#description: create by vincen
#!/bin/bash
#chkconfig: 2345 20  80
#description: create by vincen
if [ $# -ne 1 ];then
        echo $"usage:$0 {start|stop|restart}"
        exit 1
fi

if [ "$1" = "start" ];then
        rsync --daemon
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -ge 1 ];then
                echo "rsyncd is started."
                exit 0
        fi
elif [ "$1" = "stop" ];then
        killall rsync
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -eq 0 ];then
                echo "rsyncd is stopped."
                exit 0
        fi
elif [ "$1" == "restart" ];then
        killall rsync &>/dev/null
        sleep 1
        killpro=`netstat -lntup|grep rsync|wc -l`
        rsync --daemon
        sleep 1
        startpro=`netstat -lntup|grep rsync|wc -l`
        if [ $killpro -eq 0 -a $startpro -ge 1 ];then
                echo "rsyncd is restarted."
                exit 0
        fi
else
        echo $"usage:$0 {start|stop|restart}"
        exit 1
fi

 

[root@rhel6 ~]# chkconfig --list rsyncd
service rsyncd supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add rsyncd')
[root@rhel6 ~]# chkconfig --add rsyncd
[root@rhel6 ~]# chkconfig --list rsyncd
rsyncd          0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

转载于:https://www.cnblogs.com/vincenshen/p/6588862.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值