Linux under Automatic FTP-to-server comparison copy files under specified directories

Source: Internet
Author: User

Tag:shell   linux    Compare files    ftp automatically copy    

#!/bin/bashprocess=8pwd= ' pwd ' dat= ' date ' ftpip= "192.168.1.1" user= "Ftp_username" password= "Ftp_password" local_dir= "/home/" GetList () {ftp-n $ftpip <<eof |awk ' {print $9} ' |sed '/^$/d ' > $PWD/listuser $user $passwordcd File/dirbye Eof}copy () {if [-F $PWD/list]thenunset ifor i in ' cat $PWD/list|sed-n ' $star ', ' $end ' P ' doif [-F $local _dir/file/$i]th Enecho "$i file exist ..." elsewget-c-t 0-t 1800-r-nh-nv-p $local _dir ftp://"$user": "$password" @ $ftpip/file/"$i" Fido Neelseecho "list is not exist" fi} #judge ipping $ftpip-C 1 >> $PWD/copy.logres= ' echo $? ' If [x ' $res '! = X ' 0 ']thenpri NTF "\033[40;31;1mthe address cannot connect!\n\033[0m" |tee-a $PWD/copy.logexit 1elseecho "IP is OK" >> $PWD/COPY.L Ogfigetlisttotal= ' cat $PWD/list |wc-l ' perno= ' expr $total/$process ' leftno= ' expr $total% $process ' #judge processif ["$l  Eftno "-ge" $perno "]thenprintf" \033[40;31;1mtoo many process!\n\033[0m "|tee-a $PWD/copy.logexit 1elseecho" Process No. Is ok! ">> $PWD/copy.logfi## #step= ' expr $process + 1 ' star=1end= $pernoecho $DAT >> $PWD/copy.logfor ((a=1;a<= $step; a++)) Doecho "rocess: $a FILES: $star $end ">> $PWD/copy.logcopy" ">> $PWD/copy.log 2>&1 &star= ' expr $star + $perno ' end= ' Expr $end + $perno ' doneprintf ' \033[40;32;1mnow is copying in backgroud,you can use ' ps-elf ' to check...\n\033[0m

A simple script that implements a file comparison between different servers in a specified directory, the same as the file exists, does not exist in the copy to the local development directory. The number of processes, directories can be modified according to their own needs.

This article is from the "Technical Exchange" blog, please be sure to keep this source http://linuxsuperman.blog.51cto.com/2219295/1412622

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.