Using wget to save sequential files as well as renaming the file extension

wget

I run a cron job that requests a snapshot from a remote webcam at a local address:

wget http://user:pass@10.0.0.50/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?

Best Answer

You could probably torture wget into doing it, but why bother? Try

wget http://user:pass@10.0.0.50/snapshot.cgi
mv snapshot.cgi snapshot-`date +%Y-%m-%d-%H%M%S`.jpeg

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:

wget -O snapshot-`date +%Y-%m-%d-%H%M%S`.jpeg http://user:pass@10.0.0.50/snapshot.cgi

But most of me still prefers the UNIX way of doing it with small, discrete tools.