Update: 7/1/2016 - I got it working, updating the script here to reflect a working copy. Updated the post to reflect the changes.
Scenario: Customer jailed SFTP server. We receive multiple customer data feeds at unscheduled hours that need processing.
Requirement: Move files out of the jailed SFTP location so the back office can process them. They are copied locally on the system to a shared directory.
Issue: The script works as expected, the only thing that is slightly noisy is the email notifications are sent per incoming file, so if your customer is dropping off multiple files, and you do not want a single email per file, comment out the email part. I have not figured out a way around this, since its all happening in the persistent inotifywait cycle.
Here is the script;
#!/bin/bash destination="/opt/customers/customer1/inbox/" source="/opt/jail/customer1/inbox" archive="/opt/customers/customer1/archive" logfile="/tmp/log.out" tmpfile="/tmp/tmp_file.out" mail_recipients="user@domain.com" inotifywait -m --format '%f' -e close_write $source/ | while read FILE do echo `date` >> $logfile echo $FILE >> $logfile if [ $(echo $FILE | grep '^CUSTFILE') ] then cp $source/$FILE $destination echo "$FILE has been moved to the CustomerShare" >> $logfile mv $source/$FILE $archive echo "$FILE has been Archived" >> $logfile echo "$FILE" >> $tmpfile else echo "ALERT!!: Something went wrong" >> $logfile fi mailx -s "The following WOW files arrived and were placed on the CustoemrShare." $mail_recipients < $tmpfile rm $tmpfile done
Enjoy.
[link] [comments]