#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    How to send an email to a group of email id or any email group


    Below is my shell script that is working fine.

    Code:
        #!/bin/bash
        
        DATE_YEST_FORMAT2=`perl -e 'use POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*96);'`
        echo $DATE_YEST_FORMAT2
        
        QUERY1=`hive -e "
        set mapred.job.queue.name=hdmi-technology;
        SELECT SUM(total_items_purchased), SUM(total_items_missingormismatch) from lip_data_quality where dt='$DATE_YEST_FORMAT2';`
        
        QUERY2=`hive -e "
        set mapred.job.queue.name=hdmi-technology;
        SELECT 100 * SUM(total_items_missingormismatch*1.0) / SUM(total_items_purchased) FROM lip_data_quality where dt='$DATE_YEST_FORMAT2';"`
        
        echo "Total items purchased: `echo $QUERY1 | awk '{print $1}'`"
        echo "Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`"
        echo "Error Percentage: $QUERY2"

    I am running the above shell script like this below-

    Code:
    sh -x test.sh
    Problem Statement:-

    From the above shell script, I am getting below three things from the last three echo statements-

    Code:
        Total items purchased
        Total Items MissingorMismatch
        Error Percentage

    I need to send all these above three things in an email to our email group we have `DL-host@company.com` by using that `shell script` above or suppose if I have `10 email list` to which I need to send email with the same contents and subjects, then I think, I can store all these 10 emails list in some variable and just read it from there and keep on sending, right?. Is this possible to do it? I was thinking email structure like this below, just making very simple.

    Subject

    Code:
    Test Data
    Mail Body

    Code:
        Total items purchased:-    Some Number
        Total Items MissingorMismatch:-   Some Number
        Error Percentage:-   Some Number

    Any thoughts will be appreciated.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    This is an example of using a function in your shell script to email, you don't have to use an attachment I just included that if so needed, you could put the data in the 'body' variable:
    Code:
    # function: email_file is used to email file to recipients
    email_file ()
    {
    mutt -s "$SUBJECT" ${RECIPIENTS} ${ATTACHED_FILE} <<EMAIL 2>>${LOG_FILE_PATH}${LOG_FILE}
    ${BODY}
    EMAIL
    email_file_es=$?
    return
    }

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo