BASH and Rundle Mall
So… I am going to Adelaide very soon. On Friday, to be precise. (I am very excited!) Searching through tourist information on the city, I came across a publicly accessible web-cam feed for Rundle Mall. After finding this, I thought to myself “Wouldn’t it be cool if when I was in Adelaide, I got a photo of me and my friends taken by this web-cam.” Unfortunately, there is a bit of a logistical problem here: How can I save the current web-cam shot when I am standing in Rundle Mall?
Enter BASH scripting. With a few lines of BASH code, it is possible to save the current web-cam shot at a set interval for an indefinite period.
#!/bin/bash
#A short script to download timed snapshots of a file that undergoes regular updates.
#The url of the file
url="http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundle.jpg"
#This expression extracts the suffix part of the url from the url
suffixpart=${url##*.}
#The interval at which the file is fetched.
#N.B. Some sites may not take kindly to short intervals.
interval=5s
#Determine which command should be used for downloading given the current platform.
systemname=`uname -s || uname`
case $systemname in
*Linux)
cmd="wget $url -O"
;;
*Darwin)
cmd="curl $url -o"
;;
*)
cmd="wget $url -O"
;;
esac
#Infinite loop that does the downloading.
#The script must manually be interrupted to halt.
while [ 1 ]
do
datepart=`date "+%H%M%S"`
$cmd $datepart.$suffixpart
sleep $interval
done
The URL of the web-cam feed that the script downloads is easily changed by setting url (line 6) to a different URL string. Changing the interval at which snapshots are taken is similarly simple. I’ve made an effort to ensure that the script is compatible with a variety of platforms by performing a run-time check but it is likely that the script may not work on platforms other than Darwin (Mac OSX) as this was the testing platform.
Now all that remains is to leave this script running on a friend’s computer with web-access whilst visiting Rundle Mall. By syncing a watch to the system time on the computer, it will even be possible to know which shots are relevant without viewing all the snapshots individually (as the filename for each snapshot reflects when it was taken).

Leave a Reply