linux - shell script to increment file names when a directory contents changes (centos) -


i have folder containing 100 pictures webcam. when webcam sends new picture, want 1 replace number 0 , have other jpg's move 1 number. i've set script inotify monitors directory. when new file put directory script renumbers files in picture directory, renames new uploaded picture , puts in folder rest. script 'sort of' works. 'sort of', because it's supposed , complains missing files:

mv: cannot stat `webcam1.jpg': no such file or directory

sometimes complains 1 file, 4 or 5. of course made sure 100 files there, named before script run. after script run, files complains indeed missing. script, in version tested full paths directories used of course.

#!/bin/bash dir1= /foo # directory watched while inotifywait -qqre modify "$dir1"; cd /f002 #directory images in {99..1}  j=$(($i+1))  f1a=".jpg"  f1="webcam$i$f1a"  f2="test"  f2="webcam$j$f1a"  mv $f1 $f2  done rm webcam100.jpg mv dir1/*.jpg /f002/webcam0.jpg  done 

i need implement error checking, don't understand why missing files there.

you executing following mv commands:

mv webcam99.jpg webcam100.jpg ... mv webcam1.jpg webcam2.jpg 

the mv webcam0.jpg webcam1.jpg missing. first change "$dir" have following files in /foo2:

webcam99.jp ... webcam2.jpg webcam0.jpg 

with subsequent "$dir" change have following:

webcam99.jp ... webcam3.jpg webcam0.jpg 

in other words -- forgetting move webcam0.jpg webcam1.jpg. modify script this:

rm webcam99.jpg in {98..0}      j=$(($i+1))      f1a=".jpg"      f1="webcam$i$f1a"      f2="test"      f2="webcam$j$f1a"      mv $f1 $f2  done mv dir1/*.jpg /f002/webcam0.jpg  

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -