ftpサーバーを指定してftpサーバーからファイルを転送するためにbashシェルのシェルスクリプトを作成する必要があります
--fileserver@example.comuseruser1
password pass1
現在、ftpサーバーの/ dir1 / dir2に、次の形式のフォルダーがあります
0.7.1.70
0.7.1.71
0.7.1.72
最新のフォルダ、この場合は0.7.1.72からファイル「file1.iso」をコピーする必要があります。また、コピー中にファイルの整合性を確認する必要があります。つまり、ファイルがサーバーにアップロードされていると仮定します。そのときにコピーを開始すると、コピーは完了しません。
私は4時間ごとにそれをしなければなりません。これは、cronジョブにすることで実行できます。助けてください
私はこれを行いました。ftpサーバーフォルダをローカルマシンにマウントしました。ファイルが完全にアップロードされているかどうかを確認するために、50秒ごとにサイズを5回確認しています。同じ場合はコピーします。それ以外の場合は、4時間後にスクリプトを実行します...テキストファイル「foldernames」を維持しています。必要なファイルをコピーしたすべてのフォルダの名前が付いている.txt"..したがって、foldername.textファイルでその名前を確認することにより、サーバーに新しいフォルダが追加されているかどうかを確認しています.. **
すべてが正常に機能している唯一の問題は..ファイルがダウンロードされていたときにネットワーク障害が発生したと仮定します..ファイルを完全にダウンロードしたことを確認するにはどうすればよいですか....md5sumとchksumを使用しようとしましたしかし、マウントされたフォルダでの計算には時間がかかりました。助けてください
これが私のスクリプトです..
#!/bin/bash
#
# changing the directory to source location
echo " ########### " >> /tempdir/pvmscript/scriptlog.log
echo `date`>> /tempdir/pvmscript/scriptlog.log
echo " script is strting " >> /tempdir/pvmscript/scriptlog.log
cd /var/mountpt/pvm-vmware
#
# array to hold the name of last five folders of the source location
declare -a arr
i=0
for folder in `ls -1 | tail -5 `; do
arr[i]=$folder
#echo $folder
i=$((i+1))
done
echo " array initialised " >> /tempdir/pvmscript/scriptlog.log
#
#now for these 5 folders we will check if their name is present in the list of copied
# folder names
#
echo " checking for the folder name in list " >> /tempdir/pvmscript/scriptlog.log
## $(seq $((i-1)) -1 0
for j in $(seq $((i-1)) -1 0 ) ; do
var3=${arr[$j]}
#var4=${var3//./}
echo " ----------------------------------------" >> /tempdir/pvmscript/scriptlog.log
echo " the folder name is $var3" >> /tempdir/pvmscript/scriptlog.log
#
# checking if the folder name is present in the stored list of folder names or not
#
#
foldercheck=$(grep $var3 /tempdir/pvmscript/foldernames.txt | wc -l)
#
if test $foldercheck -eq 1
then
echo " the folder $var3 is present in the list so will not copy it " >> /tempdir/pvmscript/scriptlog.log
foldercheck=" "
continue
else
#
echo " folder $var3 is not present in the list so checking if it has the debug.iso file ">> /tempdir/pvmscript/scriptlog.log
#enter inside the new folder in source
#
cd /var/mountpt/pvm-vmware/$var3
#
# writing the names of content of folder to a temporary text file
#
ls -1 > /var/temporary.txt
#checking if the debug.iso is present in the given folder
var5=$(grep debug.iso /var/temporary.txt | wc -l)
var6=$(grep debug.iso //var/temporary.txt)
#
check1="true"
#
# if the file is present then checking if it is completely uploaded or not
#
rm -f /var/temporary.txt
if test $var5 -eq 1
then
echo " it has the debug.iso checking if upload is complete ">>/tempdir/pvmscript/scriptlog.log
#
# getting the size of the file we are checking if size of the file is constant or changing # after regular interval
#
var7=$(du -s ./$var6 |cut -f 1 -d '.')
#echo " size of the file is $var7"
sleep 50s
#
# checking for 5 times at a regular interval of 50 sec if size changing or not
#
#
for x in 1 2 3 4 5 ;do
var8=$(du -s ./$var6 |cut -f 1 -d '.')
#
#if size is changing exit and check it after 4 hrs when the script will rerun
#echo " size of the file $x is $var7"
if test $var7 -ne $var8
then
check1="false"
echo " file is still in the prossess of being uploadig so exiting will check after 4 hr " >> /tempdir/pvmscript/scriptlog.log
break
fi
sleep 50s
done
#
#if the size was constant copy the file to destination
#
if test $check1 = "true"
then
echo " upload was complete so copying the debug.iso file " >> /tempdir/pvmscript/scriptlog.log
cp $var6 /tempdir/PVM_Builds/
echo " writing the folder name to the list of folders which we have copied " >> /tempdir/pvmscript/scriptlog.log
echo $var3 >> /tempdir/pvmscript/foldernames.txt
echo " copying is complete " >> /tempdir/pvmscript/scriptlog.log
fi
#else
#echo $foldercheck >> /vmfs/volumes/Storage1/PVM_Builds/foldernames.txt
else
echo " it do not have the debug.iso file so leaving the directory " >>/tempdir/pvmscript/scriptlog.log
echo $var3 >> /tempdir/pvmscript/foldernames.txt
echo
fi
#rm -f /var/temporary.txt
fi
done