Currently, my script downloads the source 开发者_StackOverflow中文版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
Your really should do that with a cron entry. infinite loops are evil.
This is an infinite loop:
while sleep 1
do
perform_check
done
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
精彩评论