Skip to content

Instantly share code, notes, and snippets.

@thelebster
Forked from james2doyle/timercam.sh
Created May 6, 2017 10:23
Show Gist options
  • Select an option

  • Save thelebster/b15acc9a5bbb0069c08e2a508711bec3 to your computer and use it in GitHub Desktop.

Select an option

Save thelebster/b15acc9a5bbb0069c08e2a508711bec3 to your computer and use it in GitHub Desktop.
A script for taking a picture using the Raspberry Pi webcam tool and then using rsync to send those files to a remote server
#!/bin/bash
# must have fswebcam installed
command -v fswebcam >/dev/null 2>&1 || {
echo "I require fswebcam but it's not installed. Aborting." >&2; exit 1;
}
# must have rsync installed
command -v rsync >/dev/null 2>&1 || {
echo "I require rsync but it's not installed. Aborting." >&2; exit 1;
}
echo "Taking photo..."
# timestamp for the new file
TIMESTAMP=$(date +%s)
# the output path + filename
IMAGENAME="/home/pi/webcam/images/image-$TIMESTAMP.jpg"
# the size of the screenshot to take
fswebcam -r 640x480 --no-banner --save $IMAGENAME
echo "Saved new file at $IMAGENAME"
echo "Starting rsync..."
# src is the local folder with all the images
SRC="/home/pi/webcam/images/"
# destination location on the remote server
DEST="user@somedomain.com:/var/www/html/website/webcam/images/"
# the command to use to move the files
rsync --update --archive --delete --recursive --compress --progress --chown=www-data:www-data --chmod=u=rwx,g=rx,o=rx $SRC $DEST
echo "✔ Complete!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment