Today, there is a server a who wants to transfer all the website programs to another server b, but it is only 1 hour before the time to get off work. In order to get off work on time, I simply wrote a shell script to monitor whether the transmission was completed. I first looked at the total size of the website program on server a. It is 12G, and I use du -sm to view it, which is 11517. No one will pass on the server again, so I can rest assured that the capacity will not increase again.
System:centos
Required software: rsync
Script content:
#!/bin/bash
file=`du -sm /var/www/vhosts/|awk '{print $1}'`
ps=`ps -C rsync --no-header|wc -l`
if [ "$file" = "11517" ];then
echo "files downloaded!"
else
if [ "$ps" = "1" ];then
kill -9 $(ps aux | grep rsync |grep -v grep| awk '{print $2}')
sleep 1
nohup sh /root/ &
else
echo "rsync is running..."
fi
fi
The general idea of the script is to check whether the size of the folder is the same as that of server a. If it is different, check whether the rsync process is running. If it is not running, kill it, and then execute the rsync download script again.
ps: Of course, this script is a bit simple and does not detect the process status. If a zombie process appears, there is no way to deal with it. Of course, I will not modify it here, everyone can modify it yourself.