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:

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:

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:

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

Hi,
Could this help you ?

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

It works man.

Thanks a lot!!!!