shell exercises 22 questions:

[1] How

A ssh server may be directly added to B, and no password. A and B have a directory is / data / web / This time there are a lot of documents, we do not know how many layers below the directory, but before the directory structure and file are exactly the same. But now uncertain whether the same.

So in A standards, testing different AB file to see which files are being modified

[Core] Points

md5sum file

【script】

#! / bin / the bash 

the dir = / Data / Web 
[ -f /tmp/md5.list] && RM -f / tmp / md5.list 

the while Read Line
 do 
    the md5sum $ Line >> / tmp / md5.list
 DONE </ tmp / md5.list 

# B copied to the server 
echo  " SCP /tmp/md5.list B: / tmp " 

# embedded documents the EOF 
[ -f / tmp / check_md5. SH ] && RM -f / tmp / check_md5. SH 

CAT > / tmp / check_md5. SH << EOF 
# ! / bin / bash
 dir = / the Data / Web
while read line 
do
    file_name=`echo \$line | awk '{print $2}'`
    md5=`echo \$line | awk '{print $1}`
    if [ -f $file_name ]; then
        md5_b=`md5sum \$file_name`
        if [ \$md5_b != \$md5_b ]; then
            echo "\$file_name changed."
        fi
    else
        echo "\$file_name lose."
    fi
done < /tmp/md5.list
EOF

echo "scp /tmp/check_md5.sh B:/tmp/"
echo 'ssh B "/bin/bash /tmp/check_md5.sh"'

 

Guess you like

Origin www.cnblogs.com/dingzp/p/10991551.html