#!/bin/bash
# 2024-09-07
if [ $# -ne 1 ]
then
echo "Usage: $1 {start|stop|restart}"
exit 1
fi
if [ "$1" = "start" ]
then
/usr/bin/rsync --daemon
sleep 2
if [ `netstat -tunlp | grep rsync | wc -l` -ge 1 ]
then
echo "Rsync is starting..."
exit 0
fi
elif [ "$1" = "stop" ]
then
ps -ef | grep rsync | grep -v grep | awk '{ print $2 }' | xargs kill -9
echo "Rsync is stopping..."
exit 0
elif [ "$1" = "restart" ]
then
ps -ef | grep rsync | grep -v grep | awk '{ print $2 }' | xargs kill -9
echo "Rsync is stopping..." && sleep 1
/usr/bin/rsync --daemon && sleep 2
if [ `netstat -tunlp | grep rsync | wc -l ` -ge 1 ]
then
echo "Rsync is starting..."
fi
else
echo "Usage: $1 {start|stop|restart}"
exit 1
fi
参考来源:
https://www.bilibili.com/video/BV1d34y1j763/?p=47&spm_id_from=pageDriver&vd_source=6dc445c1be9dad41cefb811dae015c1b