I run a cron job that requests a snapshot from a remote webcam at a local address:
wget http://user:[email protected]/snapshot.cgi
This creates the files snapshot.cgi
, snapshot.cgi.1
, snapshot.cgi.2
, each time it's run.
My desired result would be for the file to be named similar to file.1.jpg
, file.2.jpg
. Basically, sequentially or date/time named files with the correct file extension instead of .cgi
.
Any ideas?
You could probably torture wget into doing it, but why bother? Try
This should create date-and-time stamped images like
snapshot-2011-04-12-081649.jpeg
. Will that do?Edit: OK, not too much torturing is required:
But most of me still prefers the UNIX way of doing it with small, discrete tools.
You can do this with a simple bash loop and the
-O
option in wget.Something like this:
One obvious annoyance is that if you already have a file.1.jpg in the directory and you start this script, it will be overwritten. To deal with that, you first need to find all the existing file.N.jpg files, find the largest value for N, and start at N+1. Here's an incredibly braindead way to do that:
Really I should rewrite this whole thing as a perl one-liner but I'm tired and it's late so I'll be lazy. Anyway that should give you an idea of how to accomplish this with a simple shell script mechanism.