Skip to content

Instantly share code, notes, and snippets.

@tspspi
Created October 2, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspspi/cf0e7df7831940348da65fc5473b22bd to your computer and use it in GitHub Desktop.
Save tspspi/cf0e7df7831940348da65fc5473b22bd to your computer and use it in GitHub Desktop.
Periodically fetching webcam images (JPEG) with wget and cron
#!/bin/sh
# === BEGIN CONFIGURATION ===
# Capture source
url="https://www.wien.gv.at/webcam-inselcam/inselcam.jpeg"
# Capture destination and timestamp format
currentdate=`date +"%Y%m%d-%H%M%S"`
fpath="/usr/home/tsp/downimg/"
fname="donauinselwien-${currentdate}.jpg"
expectedtype="image/jpeg"
verbose=0
# Tool configuration (if not in path)
binwget="/usr/local/bin/wget"
# === END CONFIGURATION ===
# Download script follows.
# First check wget is available
if [ ! -x "${binwget}" ]; then
echo "Error: wget is not executable or nonexistent at ${binwget}"
return 250
fi
# Download file (quitely)
${binwget} -q -O ${fpath}${fname} ${url}
# Check result is what we want ... first validate return code
# then check filetype
if [ $? -ne 0 ]; then
# Error. Delete file in case wget has written anything ...
rm ${fpath}${fname}
return 1
else
# Check filetype
ftype=`file --mime-type -b "${fpath}${fname}"`
if [ "$ftype" == "${expectedtype}" ]; then
if [ ${verbose} -ne 0 ]; then
echo "SUCCESS: Fetched ${url} into ${fpath}${fname} (type ${ftype})"
fi
return 0
else
# Wrong type. Delete the file.
echo "Invalid filetype ${ftype} (expected ${expectedtype})"
rm ${fpath}${fname}
return 2
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment