To trigger a mail if the files have been received


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To trigger a mail if the files have been received
# 1  
Old 01-10-2013
To trigger a mail if the files have been received

Hi All,

i have a folder in which we receive 6 files daily. the file name will be appended with date for ex : files that we receive on 1/9/2013 will be like file1_20130108.txt.zip
file1_20130108.txt
file2_20130108.txt.zip
file2_20130108.txt
file3_20130108.txt.zip
file3_20130108.txt
the job that needs this file will start on 10 Am so i want a script that check the arrival of these files from 9:30 to till all the 6 files received and trigger a mail stating that all 6 files have been received. and if we have nt received all the files till 9:45 we should get a mail that the files are not yet arrived. pleae help.
# 2  
Old 01-10-2013
what you tried so far?
# 3  
Old 01-10-2013
HI Itkamaraj,

thought of adding a crontab entery at 9:30 am everyday to send mail which excutes the command ls -ltr.

---------- Post updated at 01:50 AM ---------- Previous update was at 01:38 AM ----------

Code:
until [[ -f file1_txt.zip && -f file1.txt && -f file2.txt.zip && -f file2.txt ]]
do
sleep 60
done
#Once file arrives, send e-mail with details
ls -lrt | tail -1 | mailx -s " files arrived" dummy.dum.com
touch /filearrived.txt

will this check the files and send me a mail.
# 4  
Old 01-10-2013
schedule the below script at 09:45. So that you will get a mail, if any of the file is not arrived in that particular folder.

Code:
 
#!/bin/bash
#Find the YESTERDAY date. (below is the GNU date command)
YESTERDAY=$(date -d "YESTERDAY" +%Y%m%d)
DIR=/tmp/dir/to/watch
FILE_LIST=/tmp/filelist.txt
LS_OUT=/tmp/$$.out
MAIL_OUT=/tmp/mail.$$
ls -1 ${DIR} > ${LS_OUT}
while read FILENAME
do
 FILENAME=${FILENAME}_${YESTERDAY}.txt
 echo "Checking for ${FILENAME}
 grep "^${FILENAME}$" ${LS_OUT} && echo "${FILENAME} is available" >> ${MAIL_OUT} || echo "${FILENAME} is not available" >> ${MAIL_OUT}
 FILENAME=${FILENAME}_${YESTERDAY}.txt.zip
 echo "Checking for ${FILENAME}
 grep "^${FILENAME}$" ${LS_OUT} && echo "${FILENAME} is available" >> ${MAIL_OUT} || echo "${FILENAME} is not available" >> ${MAIL_OUT}
done < ${FILE_LIST}
grep "not" ${MAIL_OUT} >/dev/null && mailx -s "File status at 09:45" abc@xyz.com < ${MAIL_OUT}

/tmp/filelist.txt should contain the below contents
file1
file2
file3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Invoke a shell script in case mail with a specific subject is received

Hello fellow forum members, I have a script which returns a date (I can design the script to return the value in email), How can I design the script in AIX to invoke another shell script which performs some set of actions. Procmail doesnt work in AIX. (4 Replies)
Discussion started by: ektubbe
4 Replies

2. UNIX for Dummies Questions & Answers

How to count no. of received data of any one files?

Hi Guys, I have a file where is different task_id and every task id has many received data, now we have to count no. of received data for any task_id. (received means received words, i.e. count no. of received word of any task_id) Please help us Guys. (5 Replies)
Discussion started by: aaditya321
5 Replies

3. UNIX for Dummies Questions & Answers

Script to monitor BI service and trigger a mail

Hello friends, I am new to shell scripting.I am assigned a task in Unix to prepare a script which will check if OBI 10g services are running or not and to send email if the services are down.Any help will be appreciated. I tried searching for it in the blog and came across the following code ... (1 Reply)
Discussion started by: pradeep467
1 Replies

4. Solaris

Mail from mailx not received

Hi , I'm trying to send a mail from a sunOS machine that is within hp network to my email: eman.el-badawy@hp.com ,the user trying to send is 'project',,but seems the mail address can not be resolved checking /var/log/syslog i got the following: Dec 25 14:34:02 svddev15 sendmail: ... (1 Reply)
Discussion started by: Eman_in_forum
1 Replies

5. Shell Programming and Scripting

how to grep the time of the mail received?

Hi all, My question is how can we grep the time of the mail which we receive in our inbox? like if i get a mail tonight at 10 i should be able to grep the time of it tomorrow morning or someother day in 24 hr format.... how can we do that? (2 Replies)
Discussion started by: smarty86
2 Replies

6. UNIX for Advanced & Expert Users

Unknown Attachment received on html mail

Hello, Getting an extra attachment when i send a mail using below code. The body and the rest of the attachments look very fine. The extra attachment to be exact has a name ATT00001.txt. :confused: This is not part of my $attach_list. BOUNDARY='------The Boundary-----' print - "From:... (1 Reply)
Discussion started by: pgop
1 Replies

7. Shell Programming and Scripting

How do I write a ksh script that will check if all ftp files are received?

I am trying to code a ksh script that will check to see if all 26 incoming ftp files have been received before proceeding to the next function, which is to rename each file. Here is the pseudo-code of what I am trying to do: <<STEP_1>> IF all ALS files have been transmitted then... (2 Replies)
Discussion started by: doug145
2 Replies

8. AIX

Forwarding already received mail?

Greetings to all of you. I am a tad desperate here. I have found MANY articles scattered across the internet from google searches and unix.com searches for how to forward mail that say: Create a ~/.forward file and put XXXX in it. This is not what I need to do. We have bunch of users... (1 Reply)
Discussion started by: DennisC31
1 Replies

9. Post Here to Contact Site Administrators and Moderators

Received all post on my mail addess

Hi neo, I am a resistered member of Forum. I want to received all post which posted by all members via mail address. Can this possible to me??? Can i receive all posts?? Thanks Yogesh Goyal (0 Replies)
Discussion started by: yogesh goyal
0 Replies

10. UNIX for Dummies Questions & Answers

sorting received mail in unix and another error

hello! when issuing the mail command to see my received mail, i get this error: (server)starla:/home/starla>mail Warning: Too many letters, overflowing letters concatenated msgcnt 27378 vxfs: mesg 001: vx_nospace - /dev/vg00/lvol4 file system full (1 block extent) mail: no space for temp file... (0 Replies)
Discussion started by: starla0316
0 Replies
Login or Register to Ask a Question