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

What have you done so far on this. Besides post a very similar question 5 days ago?

http://www.unix.com/unix-dummies-questions-answers/83032-checking-files-ftp-location.html\#post302241054

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.

#!/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

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.

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

Excellent
It is working.
Thanks for your valuable info.
Regards,
Nimu

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 ...:slight_smile: