Skip to content

Instantly share code, notes, and snippets.

@spacekitcat
Created February 25, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spacekitcat/1bfb1f0b398da18097eefb4156150f5f to your computer and use it in GitHub Desktop.
Save spacekitcat/1bfb1f0b398da18097eefb4156150f5f to your computer and use it in GitHub Desktop.
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