I am working with a Ethernet camera that comes with Busybox.
A single board computer is connected to it through RS232. The SBC needs to send a single command to the camera in order to take a jpg snapshot, save it to a CF memory card and name it in a sequential order (0001, 0002 etc..).
This is the code I use to take a single snapshot, without sequential naming:
wget http://127.0.0.1/snap.php -O /mnt/0/snapfull`date +%d%m%y%H%M%S`.jpg
I need the files to be named sequentially. This is the code I found here that does a sequential renaming for files already existing, but I noted that when the code is executed once more after the renaming of multiple files, cross-renaming can lead to file deletion (I ran the code when files from 0001.jpg to 0005.jpg were present in the dir, and file 0004.jpg was deleted because the find cmd listed file 0005 before file 0004, so it cross-renamed both and file 0004 was deleted.)
find . -name '*.jpg' | awk 'BEGIN{ a=0 }{ printf "mv %s %04d.jpg\n", $0, a++ }' | dash
What I am looking for, is a single shell script that can be requested multiple times per day by the SBC, so that the camera takes the picture, save it and name it in a sequential order, based on the last number used (if the latest file is 0005.jpg, next picture will be named 0006.jpg).
It would be great to add this naming capability in the fisrt line of code I attached, so that I can include it in a sh script that can be called by the SBC.
This will work if and only if your filenames are all identical except for the numeric part, and the numeric part is padded enough that they're all the same number of digits.