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