Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find an email the latest output image from the motion service
#!/bin/bash
MOTION_TMP=/tmp/motion
TARGET_EMAIL=$TARGET_EMAIL_HERE
which motion
if [ ! $? -eq 0 ]
then
echo "Cannot find motion service in PATH, is it installed?"
exit 1
fi
if [ ! -d $MOTION_TMP ]
then
echo "$MOTION_TMP for motion daemon doesn't exist, is it started?"
exit 1
fi
IMAGES_TO_PROCESS=$(find $MOTION_TMP -name *.jpg -type f | wc -l)
if [ $IMAGES_TO_PROCESS -eq 0 ]
then
echo "No images to process"
exit 0
fi
IMAGE_TO_POP=$(find $MOTION_TMP -name '*.jpg' -type f | sort | head -1)
echo "Sending $IMAGE_TO_POP to $TARGET_EMAIL"
mpack -s '[motion]' $IMAGE_TO_POP $TARGET_EMAIL
rm -f $IMAGE_TO_POP
echo "$(find $MOTION_TMP -name *.jpg -type f | wc -l) images left."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment