Email Shell Script

Discussion created by bwcole on Jul 17, 2017
Latest reply on Jul 28, 2017 by bwcole

With the rich email feature within 10.0 not able to use a list within the subject, we are having to fall back to modifying our email_script to construct a dynamic subject line that will pull the first row of the alert list and include it into the subject.


What is different from running the from command line versus calling it from an APM action?


--------------- details ---------------

We are running into a problem and we are hopeful that someone in the community has already hit this issue.


We can run an from command line with no issue, and we receive an email with a well formed subject. We run the same called from a APM action and the subject line is blank.


We are reading a subject line template and replacing tokens then piping that to a subject file.  Reading in the file for the first line, which should be the fully formed subject line.  This is basically the same thing we are doing with the body.


The difference is the way we call the mail command with the values, subject, body.


   # Define the text body file with the system PID ($$) so calls won't cross over.


   # Since there are more than 9 parameters, shifting the values to get them all

# Parse of userdefined parameter
userdefined=`echo "$userdefined"|sed s/\"//g`
email=`echo $userdefined |cut -d '+' -f1`
onCall=`echo $userdefined |cut -d '+' -f2`
instSet=`echo $userdefined |cut -d '+' -f3`
lmf=`echo $userdefined |cut -d '+' -f4`
action=`echo $userdefined |cut -d '+' -f5`
if [ -z "$action" ]; then


# Build subject line
if [ -f /wilyMom/alerts/${instSet}Caution.subject ]; then
# Grab the offending value from the "text" variable.
offendingvalue=$(echo "$text" | tail -n1 | awk '{print $NF}')
# Use customer-defined subject line, if provided.
cat /wilyMom/alerts/${instSet}Caution.subject | sed -e s/::agentserver::/$agentserver/g -e s/::alertname::/$alertname/g -e s/::offendingvalue::/$offendingvalue/g -e s/::alertstat::/$alertstat/g -e s/::environment::/$environment/g >> $SUBJECT
# Use default subject line
cat /wilyMom/alerts/defaultCaution.subject | sed -e s/::alertname::/$alertname/g -e s/::alertstat::/$alertstat/g -e s/::environment::/$environment/gi >> $SUBJECT



if [ -f /wilyMom/alerts/${instSet}Caution.instructions ]; then
# Check for user-defined instructions
cat /wilyMom/alerts/${instSet}Caution.instructions |sed -e s/::environment::/$environment/g -e s/::server::/$emhost/g -e 's/EE//g' -e '/GG.*GG/d' >> $OUTPUT
# Default instructions are standard caution (SiteScope instructions)
cat /wilyMom/alerts/defaultCaution.instructions |sed -e s/::environment::/$environment/g -e s/::server::/$emhost/g -e 's/EE//g' -e '/GG.*GG/d' >> $OUTPUT


We have tried several combinations


# Read one-line SUBJECT file into $subject variable
read -r subject <"$SUBJECT"

mail -r APM_ALERT -s "$subject" $email < $OUTPUT


When ran from command line, the subject file has the right content but when we run this from action, the file and email subject is empty.


This is the user-defined parameter in the action.  The + is used for the field delimiter since , can be within the email addresses.




The third field, "defalt" is misspelled since it should never be located and the default template used.


Thank you,