Reading a file and sending mail based on content of the file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Reading a file and sending mail based on content of the file
# 1  
Old 10-03-2008
Lightbulb Reading a file and sending mail based on content of the file

Hi Gurus,
I am having an requirement. i have to read a list file which contains file names and send mail to different users based on the files in the list file.
eg. if file a.txt exists then send a mail to a@a.com
simillary for b.txt,c.txt etc.

Thanks for your help,
Nimu
# 2  
Old 10-03-2008
What have you done so far on this. Besides post a very similar question 5 days ago?

https://www.unix.com/unix-dummies-que...#post302241054
# 3  
Old 10-03-2008
What tools are you familiar with?

Being a PERL fan, I'd set up a cron job that executed a PERL script.
The script would open the directory and loop through the files. Any file that matched a
pattern would probably be moved to a processed directory and then I'd construct and send the email.

Without knowing more about your needs, it is hard to be more specific.
# 4  
Old 10-04-2008
#!/usr/bin/ksh
LOGFILE="$PM_HOME/SessLogs/aaa_check_file_received_$l_date.log"
FILE_NOT_RECEIVED_LOG="$PM_HOME/SessLogs/aaa_extracts_not_received_on_$l_date.log"
email_to_list="a@a.com"
cd $PM_HOME/TgtFiles
cat test.txt | while read line
do
if [ "${line}" = "a.txt" ]; then
echo "$line -> file not received" >> $LOGFILE
/usr/bin/mailx -s "$line file not received" $email_to_list
else
echo "$line -> extract received; " >> $FILE_NOT_RECEIVED_LOG


fi
done

This was the script i built so far.
i am getting the mail but in the body of the mail iam getting b.txt and c.txt.
But i should get a.txt instead of b.txt and c.txt.

Thanks,
Nimu
# 5  
Old 10-04-2008
The mailx command expects the body of the message as its standard input, so it reads the rest of test.txt as the email body.

To fix, supply it with an input.

Code:
echo a.txt | mailx -s "$line file not received" $email_to_list

# 6  
Old 10-04-2008
Excellent
It is working.
Thanks for your valuable info.
Regards,
Nimu
# 7  
Old 01-07-2009
I hope this would help you

You have a file file.txt
in that u have a..txt ,b.txt , c.txt

if -f file.txt
then
for i in `cat file.txt` ##Reading the file line by line
do
user_id=`basename $i txt` ##this will capture file name i.e a.txt ---> a
echo "mail_body" |mailx -s "mail_subject" $user_id@msn.com
done
else
echo "sorry file not found"
fi



I hope this will help u ...Smilie

Last edited by palanisvr; 01-07-2009 at 04:32 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. Shell Programming and Scripting

Help needed in sending file content with colors and borders

HI i am running a shell script in cron and storing the output of that script in a file say test.then i am copying the content of test to test1 and i will send the output of test to some email ids using mutt. Next time when the script executes i am comparing the contents of test and test1 and... (3 Replies)
Discussion started by: venkitesh
3 Replies

3. Shell Programming and Scripting

Problem in sending mail with database content

Hi All, I want to fetch records from Oracle DB table and send it in a mail to a set of users. i.e, I have a query which returns a set of records. I want to send mail with below content: Hi , PFB the details: <first database record> <Second database record> ……………. ………………..... (3 Replies)
Discussion started by: anil029
3 Replies

4. Shell Programming and Scripting

Mail sending with multiple attachement(pdf and csv) with html content from Linux

Hi, We have a requirement to send multiple attachment(pdf and csv) along with html content in a single mail. For that we are using uuencode. It is working for single pdf attachment and html content. But we are unable to send both pdf and csv attachment with html content. Below is the script.... (5 Replies)
Discussion started by: dholea
5 Replies

5. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

6. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

7. Shell Programming and Scripting

sending content of a file in Expect

How Can I send the content of a file in Expect? Do I have to use cat command in a way? if yes how? lets say my file is called 1.txt. example: expect "Enter command to send:" {send "???? \r"} ???? --> content of the file 1.txt (1 Reply)
Discussion started by: alireza6485
1 Replies

8. Shell Programming and Scripting

Reading a file and sending mail by shell scripting?

hi I need help urgently...i need to write a shell script which can solve the following problem....its urgent plz help me out coz m totally newbie in shell scripting.... the problem is: Suppose I have a folder called logs. whenever some error occurs some correspondence error file is generated. I... (4 Replies)
Discussion started by: sukhdip
4 Replies

9. Shell Programming and Scripting

Reading a mailbox and sending new messages to a text file

I'm new to scripting and have been tasked with creating a script that will read a mailbox, such as /var/mail/user1, scan it for new messages, then send those new messages to another file. It also has to be looped to run almost continuously. Any help would be greatly appreciated (1 Reply)
Discussion started by: rsw626
1 Replies

10. UNIX for Dummies Questions & Answers

sending mail with html content

hi, I am new to unix. I need send html content as a mail from my sun-solaris2.6 work station. When I tried that the recipient gets it as html code with all the tags. any solutions? thanx in advance (2 Replies)
Discussion started by: gmchoudary
2 Replies
Login or Register to Ask a Question