2011-11-22 38 views
0

我得到了一個腳本,用於從我的服務器下載備份。MD5腳本。如果md5check無法重試下載腳本,如何創建腳本

正在通過MD5檢查文件是否它們都是相同的。

這裏是我的腳本:

if [[ ! "$1" =~ ^[0-9]{8}$ ]] || [[ ! "$2" =~ ^[0-9\.]+$ ]] || [[ ! "$3" =~ ^[A-Z0-9]+$ ]] 
then 
    echo "Gebruik: backup_downloaden.sh jjjjmmdd ipadres naam" 
    exit 1 
fi 

cd /home/backups/Servers 

scp -i /home/backups/.ssh/dedecaan_backups [email protected]$2:$3-$1-0500.tgz.gpg . 
scp -i /home/backups/.ssh/dedecaan_backups [email protected]$2:$3-$1-0500.tgz.gpg.md5 . 
scp -i /home/backups/.ssh/dedecaan_backups [email protected]$2:$3-$1-0500.tgz.gpg.volledig . 

date > $3-$1.log 
ls -l $3-$1-* --time-style=long-iso >> $3-$1.log 
md5sum.textutils -c $3-$1-0500.tgz.gpg.md5 >> $3-$1.log 

scp -i /home/backups/.ssh/dedecaan_backups $3-$1.log [email protected]$2:$3-$1.log 
# logs altijd ook naar de productieserver kopiëren 
scp -i /home/backups/.ssh/dedecaan_backups $3-$1.log [email protected]:$3-$1.log 

我想如果檢查失敗的下載工作重新開始了。我怎樣才能做到這一點?

感謝

回答

0

讓我們來看看DOC:info coreutils 'md5sum invocation'(從該名男子頁man md5sum說):

--check」

Read file names and checksum information (not data) from each FILE 
(or from stdin if no FILE was specified) and report whether the 
checksums match the contents of the named files. 

[...]

If any listed file cannot be opened or read, 
if any valid line has an MD5 checksum inconsistent with the 
associated file, or if no valid line is found, `md5sum' exits with 
nonzero status. Otherwise, it exits successfully. 

基本上,您需要檢查返回值md5sum.textutils,如果返回值不是0,則返回到開頭。執行的最後一個命令的返回值存儲在$?中。

+0

是的,備份將從服務器啓動md5。並且該文件需要與備份相同。如果它是正確的,它會下載它。如果沒有,那麼下載將失敗。如果發生這種情況,我想要一個腳本,它在一些minuts之後再次下載它。以if語句爲例 – user1059609