First it is my first time writing a bash script so I apologize if this is trivial. I am trying to setup a watch so every time a
jpg file is uploaded to a specific folder, it gets converted to
cwebp. after googling the web, it seemed that using inotifywait is the best way (please let me know if that is not correct). reading bash script manual and inotifywait page I managed to write this code:
inotifywait -m /home/ben -e create -e moved_to | while read path action file; do # echo "The file '$file' appeared in directory '$path' via '$action'" if [[ $file = *.jpg ]] then cwebp $file -o $file.webp fi done
this works when I use for example
mv command but when using the code above, I get this error:
Could not read 0 bytes of data from file test.jpg Error! Could not process file test.jpg Error! Cannot read input picture file 'test.jpg'
if I run the command
cwebp test.jpg -o test.jpg.webp separately, it executes without any errors.
what am I doing wrong? this triggers after the file is created, why
cwebp is getting 0 bytes?