5 scripting linux debian shell bash
刚刚更新了代码......我每次都在“其他”序列上退出。您可以从我的服务器下载 update.sh 文件。它只包含回声“你好更新”
更新代码 (03.11.2015)
#/bin/bash
updateoldmd5=`sed -n l globalupdate.aix`
updatenewmd5=`md5sum update.sh |cut -d ' ' -f 1`
if [ $updateoldmd5 = $updatenewmd5 ]
then
apt-get update
echo -e $(date) "Nothing to update on this System($(hostname))." >> globalupdate.log
wget --no-check-certificate http://aixcrypt.com/vpnprofiles/services/cis/update.sh -O /root/update.sh
echo "Done"
else
chmod +x /root/update.sh
./root/update.sh
echo -e $(date) "System ($(hostname)) Updated." >> globalupdate.log
echo ""
md5sum update.sh |cut -d ' ' -f 1 > globalupdate.aix
echo "Update done"
#Get new update.sh file for next update check of the node system.
wget --no-check-certificate http://aixcrypt.com/vpnprofiles/services/cis/update.sh -O /root/update.sh
fi
Run Code Online (Sandbox Code Playgroud)
只是为了你的注意。globalupdate.aix 文件仅包含先前 update.sh 文件的 MDsum,以与新下载的文件进行比较(检查是否有任何更改适用于系统)。该脚本即将将相同的 update.sh 文件解压到许多 debian 服务器...
Dan*_* t. 18
您也可以使用cmp. 从手册页 - cmp - compare two files byte by byte. 如果文件匹配,则以 0 退出。
if cmp -s "$oldfile" "$newfile" ; 然后 echo "什么都没变" 别的 echo "有什么变了" 菲
把事情简单化。Diff 有差异时返回 1,无差异时返回 0。使用 if 语句。这是您如何区分两个文件之间的区别
if diff file1 file2 > /dev/null
then
echo "No difference"
else
echo "Difference"
fi
Run Code Online (Sandbox Code Playgroud)
要解决您的问题(您在上面的示例中比较两个变量之间的差异,请使用它(double equals 是您所缺少的)。
#/bin/bash
updateoldmd5=`sed -n l globalupdate.aix`
updatenewmd5=`md5sum update.sh |cut -d ' ' -f 1`
if [ "$updateoldmd5" == "$updatenewmd5" ]
then
apt-get update
echo -e $(date) "Nothing to update on this System($(hostname))." >> globalupdate.log
wget --no-check-certificate http://aixcrypt.com/vpnprofiles/services/cis/update.sh -O /root/update.sh
echo "Done"
else
chmod +x /root/update.sh
./root/update.sh
echo -e $(date) "System ($(hostname)) Updated." >> globalupdate.log
echo ""
md5sum update.sh |cut -d ' ' -f 1 > globalupdate.aix
echo "Update done"
#Get new update.sh file for next update check of the node system.
wget --no-check-certificate http://aixcrypt.com/vpnprofiles/services/cis/update.sh -O /root/update.sh
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41818 次 |
| 最近记录: |