#!/bin/sh
#自行管理权限
#输出同步日志
#可对比同步进度,同步好的数据,下次不再同步
daytime=$(/bin/date +%Y-%m-%d)
a=$1
b=$2
c=$3
passwd='39IDIuh7e=s'
echo "##################"`date`" $a begin rsync" >/var/log/rsync/$a.log1.$daytime
send_data_ssh(){
expect -c "
set timeout -1
spawn ssh -n rsync_rs@$a ls -l $b
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$passwd\r\";}
}
expect eof;" > /var/log/rsync/i.txt
}
send_data_ssh
cat /var/log/rsync/i.txt |grep rw|grep -v "lost+found"|awk '{print $NF}' >/var/log/rsync/new.txt
ll |awk '{print $9}' |grep -v '^$' >/var/log/rsync/now.txt
diff /var/log/rsync/new.txt /var/log/rsync/now.txt |awk '{print $2}' |grep -v '^$' > /var/log/rsync/rsync.txt
if [ -s /var/log/rsync/rsync.txt ];then
for j in `cat /var/log/rsync/rsync.txt`
do
send_data(){
expect -c "
set timeout -1
spawn rsync -rtopgvl --delete --exclude "lost+found" rsync_rs@$a:$b/$j $c
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$passwd\r\";}
}
expect eof;" >> /var/log/rsync/$a.log1.$daytime
}
send_data
done
else
echo "same floder,no need to rsync"
echo "##################"`date`" $a end rsync" >>/var/log/rsync/$a.log1.$daytime
阅读(1382) | 评论(0) | 转发(0) |