1. 首页
  2. IT资讯

shell差异拷贝(带md5检验)

—————————要求如下:———————-

192.168.123.154/oradata2/cm下的所有新的文件(包括新创建的文件夹),实现以下要求

1.文件全部拷贝到192.168.123.155下的/chi/cm

2.已经拷贝成功的文件不需要再次拷贝

实现如下:
——————————-output.sh———————
#!/bin/bash
#FILE_NAME: output.sh
#Author: chipengfei
#Date: 2012-09-17
#Usage : output.sh
#Desc: traverse the
if [ $# -lt 1 ]; then
echo ‘too few arguments’
exit
fi
function list_all()
{
cd $1
list=`ls`
for i in $list ;do
cur_path=`pwd`
echo $cur_path/$i
if [ -d $i ] ; then
list_all $i
fi
done
cd ..
}
list_all $1
———————————-diff_copy.sh——————————
#!/bin/bash
#FILE_NAME:diff_copy.sh
#Author: chipengfei
#Version: 1.0.0
#DATE: 2012-09
#DESC: Copy local files which not exists in a remote host to the remote machine.
#Usage: If need ,please modify the following variables: src_dir/src_dir2 , dest_dir/dest2, dest_host.
# initally clear used tempfile
rm -rf /tmp/node1.list /tmp/node2.list /tmp/diff.list
# the defined variables by user
src_dir=/oradata2/cm
dest_dir=/chi/cm
src_dir2=’oradata2/cm’
dest_dir2=’chi/cm’
dest_host=dbs # remote IP or hostname
src_host=`hostname` # local IP or hostname
echo “Please wait a moment, checking the file hierarchy and md5 values of machines : [${src_host}] and [${dest_host}] …”
/home/oracle/output.sh $src_dir > /tmp/node1.list
ssh $dest_host /home/oracle/output.sh $dest_dir > /tmp/node2.list
list1=$(cat /tmp/node1.list | sed “s/${src_dir2}/${dest_dir2}/g”)
list2=`cat /tmp/node2.list`
for i in $list1 ; do
flag=0
for j in $list2 ; do
if [ $i == $j ] ; then
k=`echo $i | sed “s/${dest_dir2}/${src_dir2}/g”`
if [ -f $k ] ; then
md5_src=`md5sum $k | awk ‘{print $1}’`
md5_dest=`ssh ${dest_host} md5sum $j | awk ‘{print $1}’`
if [ $md5_src != $md5_dest ] ; then
flag=0
break
fi
fi
flag=1
break
fi
done
if [ “$flag” -eq 0 ]; then
echo $i >> /tmp/diff.list
fi
done
if [ ! -f /tmp/diff.list ] ; then
echo -e ‘n###########################################################################################################’
echo ” Congratulations: the file hierarchy and md5 values of machines : [${src_host}] and [${dest_host}] are consistent!”
echo ‘############################################################################################################’
exit
fi
for i in `cat /tmp/diff.list` ; do
k=$(echo $i | sed ‘s///\//g’)
sed -i “/${k}/./d” /tmp/diff.list
done
diffs=`cat /tmp/diff.list`
for i in $diffs ; do
j=`echo $i | sed “s/${dest_dir2}/${src_dir2}/g”`
echo “scp -r $j ${dest_host}:$i”
scp -r $j ${dest_host}:$i
done
# finally clear used tempfile
rm -rf /tmp/node1.list /tmp/node2.list /tmp/diff.list
#—-End——#

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27042095/viewspace-743785/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:布吉卡,转转请注明出处:http://www.cxybcw.com/196121.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code