29. 脚本:rsync服务启停
3.5 rsync启停脚本¶
vim /etc/init.d/cp_rsync
#!/bin/bash
#author:chu peng
#输入错误的提示信息
if [ "$#" -ne 1 ];then
echo "Usage: $0 {start|stop|restart}"
exit 1
fi
#start
if [ "$1" = "start" ];then
/usr/bin/rsync --daemon
sleep 2
#检测端口
if [ `netstat -tunlp |grep rsync |wc -l` -ge 1 ];then
echo "rsync is started "
exit 0
fi
elif [ "$1" = "stop" ];then
kill all rsync &>/dev/null
sleep 2
if [ `netstat -tunlp |grep rsync |wc -l ` -eq 0 ];then
echo "rsync is stopped"
exit 0
fi
elif [ "$1" = "restart" ];then
killall rsync
sleep 1
killpro=`netstat -tunlp |grep rsync|wc -l `
/usr/bin/rsync --daemon
sleep 1
startpro=`netstat -tunlp |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
chmod +x /etc/init.d/cp_rsync
最后更新:
2022-02-19 13:59:07