Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created June 15, 2011 18:18
Show Gist options
  • Save kopiro/1027721 to your computer and use it in GitHub Desktop.
Save kopiro/1027721 to your computer and use it in GitHub Desktop.
Check a webpage everytime in Bash
#!/bin/bash
me=$(basename $0)
os=$(uname)
function usage
{
echo
echo "Usage"
echo
echo "--help OR -h: Require help"
echo "--url OR -u: Set the URL of the page"
echo "--message OR -m: Set the message to say/echo"
echo "--update: Update this script"
echo
echo "Example of usage: $me -u http://www.google.it -m Changed -s 2"
echo
}
function update
{
echo -n "$me: Downloading update.. "
sudo curl -s https://raw.github.com/gist/1027721 -o /usr/bin/webchange
sudo chmod 755 /usr/bin/webchange
echo "done."
exit
}
while [ "$1" != "" ]; do
case $1 in
-u | --url )
shift
url="$1"
;;
-m | --message )
shift
message="$1"
;;
-s | --sleep )
shift
sleep="$1"
;;
-h | --help )
usage
exit
;;
--update )
update
;;
esac
shift
done
if [ -z "$url" ]; then
echo "$me: Url not set"
usage
exit
fi
if [ -z "$message" ]; then
echo "$me: Message not set"
usage
exit
fi
if [ -z "$sleep" ]; then
echo "$me: Sleep not set. Will be set on 0 (may cause high CPU usage)"
sleep=0
fi
cd /tmp
mkdir $me
cd $me
utime="$(date +%s)"
mkdir $utime
cd $utime
echo -n "$me: Downloading referral page.. "
curl -s --user-agent "Mozilla/4.0" "$url" -o "referral.htm"
echo "done"
echo -n "$me: "
while (true); do
curl -s --user-agent "Mozilla/4.0" -H "Pragma: no-cache" "$url" -o "updated.htm"
if [ -z "$(cmp referral.htm updated.htm)" ]; then
echo -n "."
else
if [ $os == "Darwin" ]; then
say "$message"
elif [ $os = "Linux" ]; then
espeak "$message"
fi
echo "$message"
fi
sleep $sleep
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment