2011-11-22 39 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