Search code examples
bashubuntu-16.04inotifywait

Inotfiy to watch for a specific file upload , then upload all files in same sequence via ftp


I have this requirement: Client uploads csv files into a folder via SFTP. Wehn these are complete client will upload a "trigger" file to indicate that the upload is complete. I have tried to use inotifywait to wait for this trigger file then upload all csv files and this "trigger" file to another ftp server in the same sequence - ie. csv files first then trigger file. My current script just uploads whatever file is uploaded first to the ftp server and ignores the rest. My bash isnt great but I'm trying....

 #!/bin/bash
HOST='192.168.1.100'
USER='TESTUSER1'
PASSWD='password1'
FILE='\*\.csv'
TRIGGER='trigger.txt'

while TRIGGER=$(inotifywait --format '%f' -e close /home/testuser1/uploads/ ); do

ftp -n $HOST << EOT
user $USER $PASSWD
cd /home/testuser1/sftptest/
put $FILE
put $TRIGGER
quit
EOT

done
rm /home/testuser1/uploads/*.*

Solution

  • I changed while TRIGGER=$(inotifywait --format '%f' -e close /home/testuser1/uploads/ to: while TRIGGER=$(inotifywait --format '%f' -e close /home/testuser1/uploads/trigger.txt

    Simple mistake