checkForUpdates() {
checkLatest
ret=$?
if [ $ret != 0 ]; then
return $ret
fi
count=0
for i in $(ssh $__updateuser@$__updatehost "ls $__updatepath/*${latest}*"); do
file="${i##$__updatepath}"
echo "$file" >> $__debuglog
if [ -f $__pkgpath/$file ]; then
remoteHash=$(ssh $__updateuser@$__updatehost "md5sum -b < $__updatepath/${file}")
localHash=$(md5sum -b < $__pkgpath/$file)
echo "${remoteHash:0:32} = ${localHash:0:32}" >> $__debuglog
if [ "${remoteHash:0:32}" != "${localHash:0:32}" ]; then
files[$count]=$file
count=$(($count + 1))
echo "Hashes not matched, adding $i" >> $__debuglog
fi
else
files[$count]=$file
count=$(($count + 1))
echo "$file missing" >> $__debuglog
fi
done
# Verify that the files array isn't empty.
if [ $count != 0 ]; then
return 0
else
return 33
fi
}
由于某种原因,remoteHash / localHash比较始终返回true.我添加了回声,以便可以看到哈希值,并且它们肯定是不同的,而且我无法弄清楚哪里出了问题.我尝试过不同的运算符都没有成功,这让我发疯!
解决方法:
这与您的问题无关,而是更多的一般建议,首先也是最重要的you shouldn’t parse the output of ls
,而是使用find -print0,这是一个示例:http://mywiki.wooledge.org/BashFAQ/001
也可以考虑使用[[代替[参见:http://mywiki.wooledge.org/BashFAQ/031
checkLatest
ret=$?
if [ $ret != 0 ]; then
return $ret
fi
可以简单地写成:
checkLatest || return
并且您不需要在数组的索引上保留一个计数器,如果您将var初始化为一个空数组,例如files =(),则可以使用files =(“ $file”)将元素附加到它上面,用“ ${#files [@]}”计数
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。