实现一种无限 while 循环
目前,我的脚本下载 html 页面的源代码并将其保存为 plist,它检查 plist 和模板文件的 SHA 哈希值,如果哈希值不同,则删除 plist 中的一些内容,否则退出。
我想要实现的是一种无限 while 循环。虽然 SHA 哈希值相同,但它会再次下载 html 源代码,检查 SHA 哈希值,当检测到 SHA 哈希值不同时,它会删除 plist 中的一些键。
#!/bin/sh
file="/a/path/file"
a="Key1"
b="Key2"
c="Key3"
d="Key4"
declare -a array=($a $b $c $d);
cd /a/path
if [ ! -e $file.plist ]; then
curl http://something.com/ > file.plist
fi
new=`shasum file.plist`
old=`shasum orig_file.plist` # this is a template file.
if [ "$old" != "$new" ]; then
echo "Hash mismatch !"
for i in "${array[@]}"
do
defaults delete $file $i
done
else
exit 0
fi
Currently, my script downloads the source code of a html page and saves it as a plist, it checks the SHA hash of both the plist and a template file, if hashes are different, it erases some stuff in the plist, otherwise it exits.
What I would like to implement is a kind of infinite while loop. While the SHA hashes are the same, it downloads the html source code again, checks the SHA hashes, and when it detects that SHA hashes are different, it erases some keys in the plist.
#!/bin/sh
file="/a/path/file"
a="Key1"
b="Key2"
c="Key3"
d="Key4"
declare -a array=($a $b $c $d);
cd /a/path
if [ ! -e $file.plist ]; then
curl http://something.com/ > file.plist
fi
new=`shasum file.plist`
old=`shasum orig_file.plist` # this is a template file.
if [ "$old" != "$new" ]; then
echo "Hash mismatch !"
for i in "${array[@]}"
do
defaults delete $file $i
done
else
exit 0
fi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你确实应该使用 cron 条目来做到这一点。无限循环是邪恶的。
Your really should do that with a cron entry. infinite loops are evil.
这是一个无限循环:
This is an infinite loop:
如果遥控器较新,则仅下载文件的新版本是有意义的:
$curl http://something.com/ -o 文件.plist -z 文件.plist
It makes sense to only download a new version of the file if the remote is newer:
$ curl http://something.com/ -o file.plist -z file.plist