Created
October 2, 2018 22:54
-
-
Save tspspi/cf0e7df7831940348da65fc5473b22bd to your computer and use it in GitHub Desktop.
Periodically fetching webcam images (JPEG) with wget and cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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