#!/bin/bash
>1.txt;>2.txt;>3.txt
j=0
jj=0
read -p "输入要遍历的文件:" o
function fileold(){
for i in `ls $1`
do
File=$1"/"$i
if [ -f $File ]
then
# echo "$File" >> 1.txt
old=`stat -c %Z ${File}`
str1=$File:$old
echo $str1 >> 1.txt
let j+=1
else
file $File
fi
done
}
function filenew(){
for i in `ls $1`
do
File=$1"/"$i
if [ -f $File ]
then
new=`stat -c %Z ${File}`
str2=$File:$new
echo $str2 >> 2.txt
# [ $old != $new ] && scp $File 8.130.103.221:/root/1
let jj+=1
else
file $File
fi
done
}
fileold $o
sleep 10s
filenew $o
function diff_file(){
grep -vwf 1.txt 2.txt >>3.txt
for i in `cat 3.txt|awk -F: '{print $1}'`
do
scp $i 8.130.103.221:/root/1
done
}
diff_file
shell 实现递归遍历目录下所有文件并将发生变化的文件自动传输至远程机器
最新推荐文章于 2023-05-22 15:46:23 发布