Help-send mail script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help-send mail script
# 1  
Old 03-01-2011
Help-send mail script

Hi,

I have written one script for sending mails with attachment.

currently its working for only one recipient.

I want to send mails to n number of users by taking user input i.e number of users.

Output of current script:
Code:
Enter how many files : 1

Enter First Name : kiran
E-Mail ID: kiran.j@test.com

Enter file name : send_mail.sh
File Path : /apps12i/send_mail.sh

Expected output:
Code:
Enter how many files : 1

Enter number of users : 2

Enter 1 name : kiran
Email-ID:kiran.j@test.com

Enter 2 name : karan
Email-ID: karan.j@test.com

Enter file name : send_mail.sh
File Path : /apps12i/send_mail.sh

can anyone help me on this?????

Shell Script:
Code:
#!/bin/bash

subject=" File Attached "
subject1="File Not Attached"
message=" Please Find The Attachment \n
` for i in {1..5}
 do
echo  " \n"
 done `
'***' This is Auto Generated Mail Please Do Not Reply '***' \n\n\n
 Regards \n DBA. \n
"

echo -n -e "\nEnter how many files : "
read no

echo -n -e "\nEnter First Name : "
read v1

email=`cat /apps12i/mail_ids.txt | grep -e $v1 `  # prints the mail id stored in mail_ids.txt
echo "E-Mail ID: $email"

if [ -z "$email" ] || [ "$email" = " " ]
        then
                echo -n -e "\nRecipient not found !!!"
                echo -n -e "\nPlease Enter E-Mail id : "
                read email
fi

if [ $no -eq "1" ]
        then

                echo -n -e "\nEnter file name : "
                read File
                Temp=`find /apps12i -name $File`
                echo "File Path : $Temp"

                if [ -z "$Temp" ] || [ "$Temp" = " " ]
                        then

                                echo "$File File not found">message.txt
                                mutt -s "$subject1"  $email  < message.txt

                        else
                                echo "$File File found">message.txt
                                echo -ne "\n $message" >message.txt
                                mutt -s "$subject" -a $Temp  $email  < message.txt
                fi

                rm -rf message.txt

elif [ $no -gt "1" ] ;
        then
                for (( j=0; j<$no; j++ ))
                do
                        echo -n -e "\nEnter File name : "
                        read name[$j]
                done
                comm=''
                for (( j=0; j<$no; j++ ))
                do
                        FILE=`find ./ -type f -name "${name[$j]}"`
                    if [ -z "$FILE" ] || [ "$FILE" = " " ]
                then
                    echo -e "File ${name[$j]} not found\n"
                    echo -e "File ${name[$j]} not found\n" >>message.txt
                else
                    echo "File $FILE found"
                    comm=$comm" -a "$FILE
            fi
        done
                echo -ne $message >> message.txt
                mutt -s "$subject"  $comm $email  < message.txt
                rm -rf message.txt
fi


Last edited by Franklin52; 03-02-2011 at 03:23 AM.. Reason: Please use code tags
# 2  
Old 03-02-2011
Hi,
Could this help you ?
Code:
#!/bin/sh

isnumber (){
isnumeric=`expr length $(echo $1 |tr -d '0-9') 2>/dev/null`
echo $isnumeric
}
echo -n "Enter number of users:- "
read users
res=$(isnumber $users)
answer=y
while (( "$answer" == "y" ))
do
if [[ $res -gt 0 ]]
        then
                echo "--------------------------------------------------------"
                printf "\t\tYou have not entered invalid input\n"
                echo "--------------------------------------------------------"
                echo ""
                echo -n "Do you want to continue[y/n]:- "
                read answer
                case $answer in
                y|Y)printf  "\t\t\tPlease enter number...............\n\n"
                        echo -n "Enter number of users:- "
                        read users
                        res=$(isnumber $users)
                ;;
                n|N)echo "exit"
                  exit
                  ;;
                esac
        else
                break
        fi
done

for (( i=1 ; i <= $users ; i++ ))
do
echo -n "Enter Email id for user $i :- "
read email_id
all_emails=$email_id","$all_emails
done

emails=`echo $all_emails  | sed 's/.$//g'`
echo mailx -s "test email" $emails

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 03-02-2011
It works man.

Thanks a lot!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

To send a mail through shell script

I want to send a mail through shell script,If it is possible Please give me a code. mail id : upload.xxx@example.com (8 Replies)
Discussion started by: kannansoft1985
8 Replies

4. Shell Programming and Scripting

Script Contain Send Mail via Telnet

Dear Masters, I am using Solaris 10 and bash shell. I make a script for checking if a file is exists on the specified folder or not from 5th day of the month until the end of the month. If the file doesn't exist, the script will send email to me. The script ran perfectly when I execute it on... (6 Replies)
Discussion started by: kris.adrianto
6 Replies

5. Shell Programming and Scripting

script to send mail !!

Hi Experts.. i have created a table with the fields, empid name mailid 1 raja raja@xy.com and entered the values of all persons who are in that file... i have a .csv file date shift1 shift2 6/6/2011 ram raja Now i want a script that could fetch the data in (input file .csv file) and... (3 Replies)
Discussion started by: cratercrabs
3 Replies

6. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

7. Shell Programming and Scripting

Script which can send mail after its been killed

Hi Everyone, I want an script which sends mail after its been killed. Thanks (3 Replies)
Discussion started by: aki41187
3 Replies

8. Shell Programming and Scripting

shell script to send a mail

Hi, I need a shell script which runs in the backround for all the 24 hours and send a mail to us regarding the output of the prstat command when the load average increase above certain percent. kindly help me on this...... (1 Reply)
Discussion started by: jayaramanit
1 Replies

9. Shell Programming and Scripting

Script to send a mail in UNIX

Hi, I need to write one unix script gor sending a mail notification. I have to pass the followinf as arguments,from ,to,subject,messege body Can i use mailx....Please provide the code Thanks in advance. (1 Reply)
Discussion started by: sudhi
1 Replies
Login or Register to Ask a Question