I am in the process of writing a bash script that will make a POST request to a remote server every time a new file is created in a directory. I use RSYNC to sync several directories to a main directory. The main directory is then being watched by inotifywait
which will trigger a script execution when it detects new files.
The problem is the way RSYNC is creating the files I read here Rsync temporary file extension that RSYNC uses mktemp
which creates file names like .filesynced.x12fj1
but will then rename them to filesynced
after it has finished copying.
So in my inotifywait
bash script I am getting the filenames of the temp files not the filename after it has been renamed. I am wondering if someone can point me in the right direction so that I can get the filename after it has been moved and renamed.
#!/bin/bash
inotifywait -m -q -e close_write /edi-files |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
# send contents of $file to api endpoint.
done
CRON JOB:
*/1 * * * * rsync -avz --no-perms --no-o --no-g --remove-source-files /home/dir3/upload/ /home/dir2/upload/ /home/dir1/upload/ /edi-files/
CURRENT OUTPUT:
The file '.xxxxxxx1.ATM.8I2mrS' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
The file '.xxxxxxx2.ATM.MnIMPP' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
The file '.xxxxxxx3.txt.3FSceN' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
The file '.xxxxxxx4.txt.GoIDCK' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
-e move
to inotifywait's command line, you'll also receiveMOVED_FROM
andMOVED_TO
messages. – Mark Plotnick Aug 18 '17 at 17:23