Finding a file delivery time and sending it as an email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a file delivery time and sending it as an email
# 1  
Old 09-16-2009
Finding a file delivery time and sending it as an email

Hello, i have a requirement where i need to create a script which would check for a file name called XX_YYYY_ZZ in the directory inbound and as soon as the file is delivered in this directory a email needs to be sent to a user abc@yahoo.com

The plan is to put script in the core process to run it every minute to check for new files.

Thanks in advance,

Regards

RaJ

---------- Post updated at 07:16 PM ---------- Previous update was at 06:21 PM ----------

Can someone help please ?
# 2  
Old 09-16-2009
please read forum rules.
which shell you are using?
try something:


Code:
if [ -e file ];then 
 echo "file found" | mailx -s"file found" "somename@domain.com"
fi

# 3  
Old 09-17-2009
hi

thanks for your reply !

I will make it a point i reply to the concerned forum from next time around. I would appreciate if one of you could help me with the script to find the time when the file was delivered rather than the availability of the time in the directory.

TIA
# 4  
Old 09-17-2009
as you mentioned, you will run the cron in every min.
so whenever the above condition is true, you can capture the system time.


Code:
if [ -e file ];then 
 time=$(date)
 echo "file found" | mailx -s"file found" "somename@domain.com"
fi

please note it might not be the very accurate time of the file delivery.

I hope i understood you clearly.
# 5  
Old 09-17-2009
Thanks Anchal.. i think i wasnt clear earlier. An approximate time would be enough to capture. The problem is i would like to capture the details of the file which is delivered today, because the directory could contain files with older date which isnt necessary.

So logic should be something like

1) search for filename with pattern "XXX_YYY_ZZZ" since this kind of files are delivered on a daily basis. The filename will contain some characters after this pattern.
2) Check if the file is delivered today(current day)
3) If 1 & 2 are yes then the current time should be captured along with the file name.
4) Mail to someone@domain.com

Regards

RaJ
# 6  
Old 09-17-2009
something like:

Code:
latest_file=$(ls -1rt XXX_YYY_ZZZ* | tail -1)  ## ls -1 (one)
file_time=$(ls -lrt XXX_YYY_ZZZ* | tail -1 | awk '{print $6,$7}') ## ls -l (el)
 
today=$(date +'%b %d')
 
if [ "$file_time" = "$today" ];then
 ## mail
else
 ## no file today
fi

assuming you have all the files with the current year.
# 7  
Old 09-18-2009
thanks.. i am getting the following errors:

./temp.sh[3] : today: not found
./temp.sh[3] : syntax error at line 5 : 'then' unexpected
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

MIME type for sending gzip file as attachment in email

Hello, I am trying to send a gzip file on email using below command but the zipped file received on email is corrupt. mailsend -smtp $smtpip -content-type 'application/x-gzip' -mime-type "application/x-gzip" -t $receiver -f $sender -sub "$subject" -M "$MSG" -attach $file file name is ... (1 Reply)
Discussion started by: tushar.modgil
1 Replies

2. UNIX for Dummies Questions & Answers

Sending email with file names

i need to send an email to users on the files being loaded...how can i achieve this? say, my source file directory has 2 files file1.txt file2.txt I just want to send an email saying these files were loaded...Please help (1 Reply)
Discussion started by: saggiboy10
1 Replies

3. Shell Programming and Scripting

Sending a file as an attachment to email

The file is located under appl/batchdata/ file name: storesales.txt I am using following code because uuencode is not present. I am not getting the data in file but i am getting the blank file with same name as an email attachment. ( echo "from: sch@xxxx.com" echo "to:sch@xxxx.com" echo... (2 Replies)
Discussion started by: skatpally
2 Replies

4. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

5. Shell Programming and Scripting

sending email in case of file not found

Hi, In the shell script, i want to do sftp and go to a directory and check if a particular file is present, if not i send an email with some error message. Please guide me about how i could achieve it...." (1 Reply)
Discussion started by: sJohn
1 Replies

6. Shell Programming and Scripting

Attaching .csv file and sending email

I need help with writing a shell script for writing data from a table into a .csv file and send the file has email attachment. I stuck up with attaching the file to the email. Thanks, (1 Reply)
Discussion started by: Beena
1 Replies

7. Shell Programming and Scripting

Problem with sending email(to include contents of text file)

Hello, I was using a shell script for sending contents of a text file(email.report) to different users. I was using the below command in my script to send email... cat email.report | /usr/bin/mailx -s $REQ_SUBJECT -h 5 abc@xyz.com It was working fine all these days but now all of a sudden it... (18 Replies)
Discussion started by: smarty86
18 Replies

8. Shell Programming and Scripting

Sending email and attachment file using Perl

I am trying to send an email body of information and also attachment using perl script, but I am only able to send the body but not an attachment. is there around it without using "use MIME::Lite;" module. $user = "bataf\@xyz.com"; $subjectt = "mail from perl"; open(MAIL, "| mailx -s... (1 Reply)
Discussion started by: bataf
1 Replies

9. AIX

Issues on email delivery

Hello, there is a problem when using sendmail to certain destinations, basically the recipient will reject the incoming message because the user@local.domain.com is used as the sender (Return-Path), they would verify local.domain.com is not a valid DNS record which is true because it is a local... (11 Replies)
Discussion started by: neil_is_ere
11 Replies

10. Shell Programming and Scripting

Email sending attachement with two file comparision

Hi guys, I have two files . One file contains log record and another file contains emailids which is supposed to send it users File1 : Name : abc_xyz_data.txt Which contains log record File 2 : Name : abc_xyz_mailids.txt Which contains emailids. abc@test.com bcd@test.com I... (4 Replies)
Discussion started by: orabalu
4 Replies
Login or Register to Ask a Question

Featured Tech Videos