Skip to content

Instantly share code, notes, and snippets.

@bradymholt
Created November 10, 2014 02:07
Show Gist options
  • Save bradymholt/4b68c8c26bef2b2addb7 to your computer and use it in GitHub Desktop.
Save bradymholt/4b68c8c26bef2b2addb7 to your computer and use it in GitHub Desktop.
Motion Archive
#!/usr/bin/bash
# Format: YEAR MONTH DAY
DATE=$(date +%Y%m%d)
PATH="/home/bholt/surveillance/driveway"
TARGET_FILE="$PATH/$DATE"
/usr/bin/sudo /usr/bin/systemctl stop motion
/usr/bin/sudo /sbin/swapon /dev/sdb2
cd $PATH
#create timelapse video
/bin/rm $TARGET_FILE.mp4
x=1; for i in $(/bin/ls -r -t *jpg); do counter=$(printf %04d $x); /bin/ln -s "$i" img"$counter" .jpg; x=$(($x+1)); done
/usr/bin/ffmpeg -r 5 -i img%04d.jpg $TARGET_FILE.mp4
/bin/rm img*.jpg
#archive images into zip
/usr/bin/zip -m $TARGET_FILE.zip *.jpg -x \*.zip
#remove image archives and videos that are at least 10 days old
/usr/bin/find ${PATH}/* -mtime +10 -exec /bin/rm {} \;
/usr/bin/sudo /sbin/swapoff /dev/sdb2
/usr/bin/sudo /usr/bin/systemctl start motion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment