I’m using camE as my webcam software. Today I enabled its archiving feature: It can place a copy of every update into a directory so you have a set of archived pics, security camera style. Problem is, if you’re updating every 15 seconds that means your archive gets quite big (~100mb/day), so I wrote a couple of scripts to let cron keep only a subset of the images. Everything is kept for a week, after which only one photo per 5 minute block is kept. Then, after three months, only one photo per half hour is kept (these are kept forever).
These scripts assume you take four pics a minute, otherwise they will keep archives for a different length of time.
Archive after 7 days (run this once a day):
#!/bin/bash
cd /share/webcam-security-pics/current
count=0
for picture in `ls -t`
do
let "count += 1"
if [ "$count" -gt 40320 ]
then
if [ `expr $count % 20` -eq 1 ]
then
#echo "moving $picture"
mv $picture ../archived/
else
#echo "deleting picture"
rm $picture
fi
fi
done
Perma-archive after 3 months (run this once a week, say):
#!/bin/bash
# Keeping the most recent 40320 pics (12 weeks, assuming one pic every 5 minutes),
# archive 1 in every 6 pictures (representing 1 pic per 30 minutes) to the perma-archived
# directory.
cd /share/webcam-security-pics/archived
count=0
for picture in `ls -t`
do
let "count += 1"
if [ "$count" -gt 40320 ]
then
if [ `expr $count % 6` -eq 1 ]
then
#echo "moving $picture"
mv $picture ../perma-archived/
else
#echo "deleting picture"
rm $picture
fi
fi
done