There are many ways to do it. If you only receive pictures from the IP address 192.168.0.1, you could use the following script and invoke it from cron:
Code:
#!/bin/bash
cd /directory/where/the/files/may/exist
if [ $(ls 192.168.0.1*.jpeg 2>/dev/null | wc -l) -ge 2 ] # do not delete files unless two or more exist
then
rm $(ls -rt 192.168.0.1*.jpeg | head --lines=-1) # list in order of modtime, select all but the most recent, delete
fi
if [ $(ls 192.168.0.1*.jpeg 2>/dev/null | wc -l) -ge 1 ] # do not mv file unless one (or more) exists
then
mv $(ls -rt 192.168.0.1*.jpeg | tail --lines=1) mycam1image.jpeg # mv most recent file to target filename
fi
If there are no new webcam images, the script will do nothing.
If there are two or more new images, the script will delete all but the most recent.
The newest webcam image will be renamed, overwriting the target file if necessary.
If new webcam images appears after the rm and before the mv, the script will mv the most recent.
Edit: There is one problem. If there are no new files, the script generates error messages ("ls: cannot access 192.168.0.1*.jpeg: No such file or directory"), though it correctly does nothing else. The error messages can be discarded with 2>/dev/null as I have added above. There may be a more elegant method which does not generate or require special handling of these error message.