LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-14-2017, 08:59 AM   #1
GazzaRoo
LQ Newbie
 
Registered: Nov 2014
Posts: 1

Rep: Reputation: Disabled
inotify to watch for a particular file to be uploaded


I have a directory where a user will upload a number of csv fiels via sftp.
The user then has to upload a txt file to signal that all uploads are complete.
Once this txt file has been uploaded, all the csv files need to be uploaded to an internal ftp server and then the same txt file last.
I have tried writing a bash script to do this but it just uploads any file via ftp wether or no this txt file is there. Help please .......as my bash scripting sucks

Code:
#!/bin/bash
HOST='ftp.host'
USER='testuser'
PASSWD='testpword'
FILE='*.csv'
TRIGGER='trigger.txt'

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

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

rm *.csv
rm *.txt
done
 
Old 06-15-2017, 10:02 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,634

Rep: Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189
You have to test for the existence of the trigger.txt file. $TRIGGER will be assigned to any file that is created in your uploads directory.

Many ways but here is how I do it. Why do you need to upload the the trigger file?

Code:
 
#!/bin/bash
inotifywait -m -q -e close_write --format %f /home/testuser/uploads/ | while IFS= read -r file; do
   if [[ "$file" == "$TRIGGER" ]];then
       rest of ftp...
   fi
done

Last edited by michaelk; 06-15-2017 at 10:12 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
inotify -cannot add a watch to newly created directory after few levels in a directoy rex1254 Linux - Newbie 5 09-11-2014 12:46 PM
inotify to watch a directory then print and move algreig Linux - Newbie 4 05-25-2012 10:14 AM
Monitoring file system with inotify henriquetft Programming 8 10-31-2009 05:25 PM
Upload file to ftp server -vsftp- but can not delete or change the file once uploaded murattas6 Linux - Server 2 06-26-2009 06:00 AM
uploaded file on vsftpd has wrong file attributes rune.kg Linux - Newbie 2 03-06-2004 09:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration