Shell script realizes whether the rsync data is transmitted over the _linux shell

Source: Internet
Author: User
Tags rsync

Today there is a server A to transfer all the Web site program to another server B up, but away from work time is only 1 hours, in order to work on time, simply wrote a shell script to monitor whether there is transmission, I first in the server a looked at the total size of the program 12G, with Du- SM View is 11517, the server will not be someone to send things up, so I can be assured that the capacity will not become larger.

System: CentOS 5.x

Software Required: rsync

Script content:

Copy Code code as follows:

#!/bin/bash
File= ' Du-sm/var/www/vhosts/|awk ' {print $} '
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 $} ')
Sleep 1
Nohup sh/root/rsync.sh &
Else
echo "Rsync is running ..."
Fi
Fi

The general idea of the script is to see if the folder size is the same size as server A, and if not, check that the rsync process is running, kill it if it isn't running, and then rerun the download script for rsync.

PS: Of course, this script is a bit shabby, not to detect the status of the process, if there is a zombie process, there is no way to deal with. Of course, I will not change here, we can modify their own.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.