开发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