Adding the email functionality


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding the email functionality
# 1  
Old 09-22-2013
Wrench Adding the email functionality

I have make an menu in which first option is to start and second is to stop the services

Code:
 echo "Please enter the appropriate choice for doing the operations"
        echo "
        1) STOP Services        
        2) START Services 
        
    case $choice in
        1)
            echo "*************Stopping Services**************"
            stopAll.sh
            ;;
        2)
            echo "*************Starting Services**************"
            startAll.sh
            ;;


now please advise I want to add the functionality of email also in it that is lets say if some one stop the services by pressing the 1 option then a mail should be launced with the subject that services are stopped and with the body also that services are stopped at that time when the option 1 is pressed , please advise how to customize and the add the functionality of email. Smilie
# 2  
Old 09-22-2013
Blade

Quote:
Originally Posted by punpun66
I have make an menu in which first option is to start and second is to stop the services

Code:
 echo "Please enter the appropriate choice for doing the operations"
        echo "
        1) STOP Services        
        2) START Services 
        
    case $choice in
        1)
            echo "*************Stopping Services**************"
            stopAll.sh
            ;;
        2)
            echo "*************Starting Services**************"
            startAll.sh
            ;;


now please advise I want to add the functionality of email also in it that is lets say if some one stop the services by pressing the 1 option then a mail should be launced with the subject that services are stopped and with the body also that services are stopped at that time when the option 1 is pressed , please advise how to customize and the add the functionality of email. Smilie
In such case i suggest that you create a mailing code and call it. To email you can use several ways from maix to uuencode please be more specific as to what exactly you wish to achiever.
The idea way in your scenario will be if my assumptions are correct
after your start and stop scripts add the below
Code:
cat <A_TEMP_FILE> | mail -s "Subject" user@dmoain.com

If you have multiple users and DL's create a variable
Code:
MY_DL="user@dmoain.com, user1@dmoain.com"

and use it in the above command.

Good Luck
# 3  
Old 09-22-2013
Why don't you just add the mail command to each case option:
Code:
case $choice in
         1) echo "*************Stopping Services**************"
            stopAll.sh
            mail -s "service stopped" mail@domain.com
            ;;
         2) echo "*************Starting Services**************"
            startAll.sh
            mail -s "service started" mail@domain.com
            ;;

# 4  
Old 09-22-2013
Wrench

Quote:
Originally Posted by RudiC
Why don't you just add the mail command to each case option:
Code:
case $choice in
         1) echo "*************Stopping Services**************"
            stopAll.sh
            mail -s "service stopped" mail@domain.com
            ;;
         2) echo "*************Starting Services**************"
            startAll.sh
            mail -s "service started" mail@domain.com
            ;;

Thanks a lot , but I want that mail to be send to the users on their Gmail Account let say I have two accounts abcd1@gmail.com and abcd2@gmail.com so I want mail to be send to these two accounts so please advise how to send mail to these two accounts through shell script and what settings need to be configured like SMTP .Smilie

---------- Post updated at 07:38 PM ---------- Previous update was at 07:37 PM ----------

Quote:
Originally Posted by saurabh.mishra
In such case i suggest that you create a mailing code and call it. To email you can use several ways from maix to uuencode please be more specific as to what exactly you wish to achiever.
The idea way in your scenario will be if my assumptions are correct
after your start and stop scripts add the below
Code:
cat <A_TEMP_FILE> | mail -s "Subject" user@dmoain.com

If you have multiple users and DL's create a variable
Code:
MY_DL="user@dmoain.com, user1@dmoain.com"

and use it in the above command.
hanks a lot , but I want that mail to be send to the users on their Gmail Account let say I have two accounts abcd1@gmail.com and abcd2@gmail.com so I want mail to be send to these two accounts so please advise how to send mail to these two accounts through shell script and what settings need to be configured like SMTPSmilie


Good Luck
# 5  
Old 09-23-2013
you can follow what RudiC do,
but instead of add one email address.
use an email value instead
like what saurabh.mishra say:
MY_EMAIL:"user@dmoain.com, user1@dmoain.com"

then

Code:
case $choice in
         1) echo "*************Stopping Services**************"
            stopAll.sh
            mail -s "service stopped" $MY_EMAIL
            ;;
         2) echo "*************Starting Services**************"
            startAll.sh
            mail -s "service started" $MY_EMAIL
            ;;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding a blank line in between two O/Ps in tabular format which gets received over email

Hi Guys, I am stuck in between and seeking help here. Requirement: A script that will run every morning which will connect to Mysql database and run the query to inform us about the holidays (it will also check if there were any holidays during last 2 business days). So the three queries are... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

2. Shell Programming and Scripting

Adding 'from' email address alias in Linux.

Hi Experts, We want to add the 'from' email address to mailx command in all our linux script. After searching this site I am able to find the command '-- -f' to add the from the email address. Bu the problem is our from email address is :- "Proper Support Name <support@company.com>" Now when I... (6 Replies)
Discussion started by: Amey Joshi
6 Replies

3. UNIX for Dummies Questions & Answers

Sendmail with cat adding extra spaces in email body

when I try to read a file and send email using cat and sendmail: The email received having additional spaces.(Between the letters of words in the text) My code: export MAILTO="sa@y.com" export SUBJECT="mydomain PREPROD MONITOR AT ${DATE}" export... (5 Replies)
Discussion started by: visitsany
5 Replies

4. UNIX for Dummies Questions & Answers

Command Functionality

Hi everyone, today i need that someone help to understand this particular line of command. So you can explain to me step by step, it will be great. ---------- Post updated at 11:53 AM ---------- Previous update was at 11:51 AM ---------- (9 Replies)
Discussion started by: Newer
9 Replies

5. Shell Programming and Scripting

[Solved] adding email option to KSH

Hi, I wanted to add a email option to this script. and was wondering if anyone could help me out. #!/bin/ksh echo "Finding hdisk" <DIR>/find-disk i=1 b=0 p=0 while ... (2 Replies)
Discussion started by: vpundit
2 Replies

6. Shell Programming and Scripting

adding multiple email ID

Hi, I have a script running as a cron job. Is it possible to send the output to multiple user through mail. I cant add multiple mail id. _TOADDR=xxx@xxx.com;xxx@xxx.com _FROMADDR=xxx@xxx.com from=$_FROMADDR emailtarget=$_TOADDR subject=$_SUBJECT CONTENT=$1 Is it possible to send to... (1 Reply)
Discussion started by: ahamed
1 Replies

7. UNIX for Dummies Questions & Answers

using functionality in another ksh

i have a function defined in one ksh i want to use the same functionality in another ksh i am using . ../<ksh name> but it is not picking that functionality what i have to do for the same (2 Replies)
Discussion started by: trichyselva
2 Replies

8. Shell Programming and Scripting

Sed functionality

I have a few xml files and I want to input say 5 parameters within each file. is it possible to do so with sed? <parameter>A</parameter> <parameter>B</parameter> .... .... And so on. These parameters are meant to go in just inside: <?xml... (2 Replies)
Discussion started by: collern2
2 Replies

9. UNIX for Dummies Questions & Answers

Date functionality

Hi, Could someone help me to get yesterday's date in MMDDYY format. echo `date '+%m%d%y'` is giving me today's date in the above format. Thanks in advance for your help.. Suresh. (1 Reply)
Discussion started by: svannala1
1 Replies
Login or Register to Ask a Question