Script for sending notification mail

hi all,
needed a script to send a notfication mail if the specified folder had the copy of the files that are older than 15 days
i.ee for example
my folder name is SAi
and the files are as follows
sai.txt
copyofsai.txt
copyofcopyofsai.txt
hemanth.txt
copyofcopyofhemanth.txt
copyofcopyofcopyofhemath.txt

if SAI folder contains the above files and if the copy files created are older than 15 days then a notification mail should ne sent to the defined user mail address specify that you have
2 copies of sai.txt and 2 copies of heamnth.txt please remove as early s possible

thanks in advance
hemanth saikumar

These are the tools you need to know:

  1. for loop to loop through .txt files.
  2. if condition
  3. find command. In particular the -mtime switch.
  4. mailx utility.

iam new to unix shell script could u please script it..:frowning:

---------- Post updated at 05:20 AM ---------- Previous update was at 12:49 AM ----------

any idea wat to do.?

hi can anyone help me on the above issue..?

regards
vasa hemanth saikumar

hope this will help you

mail_subject="write the subject of the mail"
mail_ids="email id of the person"
main_body="file which contains mail body"

find . -type f -mtime +15 | cut -c3- | grep "^copy" > file.txt
no_file=`cat file.txt | wc -l`
if [ $no_file -ge 1 ]; then
        mailx -s "$mail_subject" "$mail_ids" < $mail_body
fi