实现一种无限while循环
问题描述:
目前,我的脚本下载html页面的源代码并将其保存为plist,它检查plist和模板文件的SHA哈希,如果哈希不同,它将会擦除一些东西在plist,否则它退出。实现一种无限while循环
我想实现的是一种无限的while循环。尽管SHA哈希值相同,但它会再次下载html源代码,检查SHA哈希值,以及何时检测到SHA哈希值不同,它会删除plist中的某些密钥。
#!/bin/sh
file="https://*.com/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
答
你真正应该做的是用cron项。无限循环是邪恶的。
答
这是一个无限循环:
while sleep 1
do
perform_check
done
的Cron需要锁定文件处理额外工作以避免重复的同时运行。 – ceving 2011-05-04 14:35:05
是的,这不是什么大不了的事。 – tamasgal 2011-05-04 14:49:36