Skip to content

Instantly share code, notes, and snippets.

@javache
Created January 28, 2013 19:03
Show Gist options
  • Save javache/4658107 to your computer and use it in GitHub Desktop.
Save javache/4658107 to your computer and use it in GitHub Desktop.
Urgent.fm motion cleanup script
#!/bin/sh
set -e
cd /home/motion
# Prevent deletion
touch cleanup-snapshots.sh
# Remove snapshots over 3 months old (3*31 = 93)
n=$(find . -type f -mtime +93 -exec rm {} \; -print | wc -l)
echo "Removed $n snapshots older than 3 months."
# Reduce interval to one every 15 minutes for snapshots older than 1 month
n=$(find . -type f -mtime +31 -not -regex '.*\(00\|15\|30\|45\)-00 ([12]).jpg' -exec rm {} \; -print | wc -l)
echo "Reduced interval to 15 minutes for snapshots older than 1 month, $n removed."
# Reduce interval to one every 5 minutes for snapshots older than 2 weeks
n=$(find . -type f -mtime +13 -not -regex '.*[05]-00 ([12]).jpg' -exec rm {} \; -print | wc -l)
echo "Reduced interval to 5 minutes for snapshots older than 2 weeks, $n removed."
# Reduce interval to one every minute for snapshots older than 3 days
n=$(find . -type f -mtime +2 -not -regex '.*-00 ([12]).jpg' -exec rm {} \; -print | wc -l)
echo "Reduced interval to one minute for snapshots older than 3 days, $n removed."
# Reduce interval to one every 30 seconds for snapshots older than 1 day
n=$(find . -type f -mtime +0 -not -regex '.*-\(00\|30\) ([12]).jpg' -exec rm {} \; -print | wc -l)
echo "Reduced interval to 30 seconds for snapshots older than 1 day, $n removed."
# Remove empty folders
find . -type d -empty -exec rmdir {} \;
# Restart motion for good measure
PATH=/usr/local/sbin:/sbin:$PATH
service motion restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment