0

フォルダに100 個のファイルがあり、/data01/primaryフォルダ内に 100 個の異なるファイルがあり/data02/secondaryますmachineX。これらの 200 個のファイルはすべてmachineAとから取得されmachineB、ファイルが にない場合はmachineA、必ず にあるはずmachineBです。

したがって、ファイルをmachineAおよびmachineB(ソース サーバー) からmachineX(宛先サーバー) にコピーします。machineA と machineB からコピーするファイルはこのディレクトリ/checkbat/data/snapshot/20140918にあるため、両方のソース サーバーにこのディレクトリがあります。

現在、machineX にある 200 個のファイルを machineA および machineB と比較して、md5 チェックサムを実行しようとしています。

ファイル パスはこのようになっています。1、2、3、4 の数字以外はすべて同じです。

t1_monthly_1980_1_200003_5.data
t1_monthly_1980_2_200003_5.data
t1_monthly_1980_3_200003_5.data
t1_monthly_1980_4_200003_5.data

上記のような 100 個のファイルが /data01/primary フォルダーにあり、100 個の異なるファイルが machineX の /data02/secondary フォルダーにあり、これは machineA と machineB から取得されます。

ここで私がする必要があるのは、/data01/primaryフォルダー内の 100 個のファイルの md5checksum をmachineAおよび内のファイルと比較することですmachineB。ファイルのチェックサムのいずれかが宛先サーバーと比較してソース サーバーで異なる場合は、ソース サーバーと宛先サーバーの両方でファイル名とそのチェックサムを出力します。

#!/bin/bash

export PRIMARY=/data01/primary
export SECONDARY=/data02/secondary

readonly DESTINATION_SERVER=(machineA machineB)
export DESTINATION_SERVER_1=${DESTINATION_SERVER[0]}
export DESTINATION_SERVER_2=${DESTINATION_SERVER[1]}

export FILES_LOCATION_ON_DESTINATION=/checkbat/data/snapshot/20140918

readonly SOURCE_SERVER=machineX

export dir3=$FILES_LOCATION_ON_DESTINATION

# compare the checksum and find the files whose checksum are different

for entry in "$PRIMARY"/*
do
    echo "$entry"
    # now how to compare the file checksum of this file with same file in machineA or machineB
done

単一のファイルで md5checksum を実行する方法は知っていますが、ネットワーク経由でファイルのチェックサムを比較する方法がわかりません。これは可能ですか?

md5sum filename

すべての ssh をセットアップしました。これらの宛先サーバーで、ソース サーバーからabcユーザーとして ssh を実行できます。

ssh abc@${DESTINATION_SERVER[0]}
4

1 に答える 1

1

このタスクを実行するには、ssh を使用します。

$ ssh user@hostname "/usr/bin/md5sum filename"
a40bd6fe1ae2c03addba2473e0bdc63b  filename

タスクを自動化したい場合は、このように変数に割り当てます。

remote_md5sum=`ssh user@hostname  "/usr/bin/md5sum filename"`

次に、 $remote_md5sum の値を使用して、動作を検証できます。

ところで、このシナリオでは秘密鍵認証を使用しているため、パスワードは必要ありません。#!/ビン/バッシュ

export PRIMARY=/data01/primary
export SECONDARY=/data02/secondary

readonly DESTINATION_SERVERS=(machineA machineB)
export DESTINATION_SERVER_1=${DESTINATION_SERVERS[0]}
export DESTINATION_SERVER_2=${DESTINATION_SERVERS[1]}

export FILES_LOCATION_ON_DESTINATION=/checkbat/data/snapshot/20140918

readonly SOURCE_SERVER=machineX

export dir3=$FILES_LOCATION_ON_DESTINATION

# compare the checksum and find the files whose checksum are different

for entry in "$PRIMARY"/*
do
    local_md5sum=`/usr/bin/md5sum "$entry" | awk '{print $1}'`

        for DESTINATION_SERVER in $DESTINATION_SERVERS
        do
                remote_md5sum=`ssh user@$DESTINATION_SERVER /usr/bin/md5sum "$entry" | awk '{print $1}'`

                # now how to compare the file checksum of this file with same file in machineA or machineB
                if [ "$local_md5sum" -eq "$remote_md5sum" ] 
                then
                        echo "match";
                else
                        echo "not match"
                fi
        done
done
于 2014-09-22T19:16:51.670 に答える