Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

| Views: 1158
As the traffic cam keeps taking photos every 5 minutes, the number of files in the archive directory quickly adds up, over the past 2 months there were around 12 thousand files. This was getting a little bit difficult to manage so I decided that it would be a good idea if the script automatically put these into directories sorted by year, month and day.

The change is quite simple, the line where the ARCH_DIR variable is set is changed to this:
ARCH_DIR=$WORK_DIR/wbrsew/`date +"%Y"`/`date +"%m"`/`date +"%d"`
mkdir -p $ARCH_DIR


The whole script looks like this now (I also changed from Wacaw to ImageSnap):
#!/bin/bash
WORK_DIR=/Users/ikromin/Downloads
ARCH_DIR=$WORK_DIR/wbrsew/`date +"%Y"`/`date +"%m"`/`date +"%d"`
mkdir -p $ARCH_DIR
WACAW="/Users/ikromin/Downloads/wacaw-04/wacaw --png -d 2 -n 3 $WORK_DIR/wbrsew_o"
ISNAP="/Users/ikromin/Downloads/ImageSnap-v0.2.5/imagesnap -w 1 $WORK_DIR/wbrsew_o.png"
CONVERT=/usr/local/bin/convert
OPTIM=/Applications/ImageOptim.app/Contents/MacOS/jpegoptim
if [ ! -d "$ARCH_DIR" ]; then
mkdir $ARCH_DIR
fi
#$WACAW
$ISNAP
$CONVERT $WORK_DIR/wbrsew_o.png -adaptive-resize 640x480> -unsharp 0x1 $WORK_DIR/wbrsew_o.jpeg
cp $WORK_DIR/wbrsew_o.jpeg $ARCH_DIR/arch_`date +"%Y%m%d%H%M%S"`.jpeg
$CONVERT $WORK_DIR/wbrsew_o.jpeg -sharpen 0x.4 $WORK_DIR/wbrsew_s.jpeg
$CONVERT $WORK_DIR/wbrsew_s.jpeg -font Arial -pointsize 14 -draw "gravity south-west fill '#00000090' rectangle 0,480 640,450 fill black text 11,8 'Riverside Expressway Cam © Igor Kromin' fill white text 10,7 'Riverside Expressway Cam © Igor Kromin' gravity south-east fill black text 11,8 'Time: `date`' fill white text 10,7 'Time: `date`' gravity north-west fill '#00000090' rectangle 0,0 640,24 fill white text 6,4 'Visit: http://www.igorkromin.net/?page=wbrsew'" $WORK_DIR/wbrsew.jpeg
$OPTIM --strip-all -m85 $WORK_DIR/wbrsew.jpeg
scp $WORK_DIR/wbrsew.jpeg [email protected]:/dir/




-i

Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...