1830356 Members
2955 Online
110001 Solutions
New Discussion

File watcher

 
la_cool
Occasional Advisor

File watcher

File watcher logic; , for instance as soon as the file is sent from External system to our internal system, email needs to be sent to respective users about the files have arrived.

Could someone help me with the script
4 REPLIES 4
Mel Burslan
Honored Contributor

Re: File watcher

# assumptions:
# files comes into /tmp/ftp/upload
# you have a directory /tmp/ftp/archive

delay=3 # in seconds wait betwwen checks
while true
do

if [ -a * ]
then
mv /tmp/ftp/upload/* /tmp/ftp/archive
echo "file(s) received" | mailx -s "New files arrived" user@domain.com
else
sleep $delay
fi

done

hope it helps
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor

Re: File watcher

sorry.. one oversight

the line with if should have read like this

if [ -a /tmp/ftp/upload/* ]

or whatever the directory name that your upload files are coming into
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor

Re: File watcher

Not until you do some more work yourself like drawing up a few specifications. Typically, the files arrive in a dedicated directory or directory tied to a particular user.

Start writing the detailed specifications and you just might find that the script all but writes itself.

If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: File watcher

Here is the approach.

1) cron runs the script. man crontab to set that up.


find /directory -name * > /tmp/filelist

while read -r rr
do
echo $rr
# if the filename meets your criteria send
# email
if [ "$mailflag" == "Y" ]
then
echo "you have a file $rr" | mailx -s "You have a file" someone@some.net
fi

done < /tmp/filelist


The find command is pretty hard on your system, I don't reccommend running it more than every five minutes.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com