I bought this really cheap webcam from DealExtreme. That camera is now providing one of my websites with live images. The cameras internal webserver can’t handle that many request, so I am using the ftp-feature to upload images to my web server.

webcam

One problem is that each photo’s filename consists of a timestamp, like ”20130404_1223.jpg”. Instead I want the filename to be something like ”webcam.jpg”. Another problem is that the ftp feature fill my webserver with too many photos, so I need to purge the upload directory.

I wrote this script that purges the upload directory from ALL but THE LATEST photo. It also renames the remaining photo to webcam.jpg as I wanted.

#!/usr/local/bin/bash
cd /path/to/webcamftp
(ls -rt *.jpg|tail -n 1;ls *.jpg)|sort|uniq -u|xargs rm
ls *.jpg | xargs -I '{}' mv '{}' webcam.jpg
Share →

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *