Created
May 2, 2017 04:42
-
-
Save james2doyle/ced42d0d365f66ea93e80e496ac85082 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
This file contains hidden or 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/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