We are using imagesnap program to take a photo from command-line. On OSX, you can install it via homebrew.
#!/usr/bin/env bash
IMAGESNAP=/usr/local/bin/imagesnap
DEVICE="HD Pro Webcam C920"
DATE=`date "+%Y%m%d"`
DATETIME=`date "+%Y%m%d_%H%M%S"`
MIN=`date "+%M"`
IMAGE_PATH=/Users/soonhok/Dropbox/Photos/GHC9232
if [[ -e ${IMAGE_PATH}/shot || -e ${IMAGE_PATH}/SHOT || `expr ${MIN} % 15` == 0 ]]
then
mkdir ${IMAGE_PATH}/${DATE} 2> /dev/null
${IMAGESNAP} -d "${DEVICE}" ${IMAGE_PATH}/${DATE}/${DATETIME}.jpg -w 5.00 -q
rm -rf ${IMAGE_PATH}/SHOT ${IMAGE_PATH}/shot > /dev/null
fi
This script takes a photo every 15
min from DEVICE
and saves them at IMAGE_PATH
. On my imac, I have an entry for crontab
to automatically run the script regularly:
1 0-59 * * * * /Users/soonhok/bin/takeshot.sh
Having too many photos on Dropbox is not a good idea. So we have another machine which backups the shared photos from Dropbox and removes them from Dropbox if they are older than 5 days
. It uses the following move_photos.sh
script:
#!/usr/bin/env bash
DROPBOX_PHOTO_DIR=/Users/soonhok/Dropbox/Photos/GHC9232
BACKUP_DIR=/Users/Shared/GHC9232_Backup
WEEK_AGO=`date -j -v-5d "+%Y%m%d"`
TOGO=${DROPBOX_PHOTO_DIR}/${WEEK_AGO}
if [ -d "$TOGO" ]
then
mv ${DROPBOX_PHOTO_DIR}/${WEEK_AGO} ${BACKUP_DIR}/
fi