フォルダに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]}