1835221 Members
2197 Online
110078 Solutions
New Discussion

scripting headache

 
Seun Ewulomi_1
Honored Contributor

scripting headache

Hi People,

I get an email sent in the event of a node down status on our routers. This passes a few variables that shows the node that went down, the time, and date e.t.c.

I currently use the snmpget command to get values of mib tables for nodes(routers) from the command line e.g

snmpget .1.3.6.1.2.1.1.3.0

I would like to incorporate a series of snmpget commands to be included in the email at the momment the command im using as automatic action(i put all this on one line) is:

ping -s $2 100 5 > /space/probpipe & echo "Subject: $A Router Down\n" > /space/probpipe & echo $A Router - Node Status $s at $x on $X Ping OUTPUT: \r > /space/probpipe & dd if=/space/probpipe | /usr/lib/sendmail -bm -F $2 ; /usr/bin/traceroute $2 > /space/probpipe & echo "Subject: $A Router Down\n" > /space/probpipe & echo $A Router Node Status $s at $x on $X Traceroute OUTPUT: \r > /space/probpipe & dd if=/space/probpipe | /usr/lib/sendmail -bm -F $2

(I KNOW ITS a MESS)

$2 and = hostname of the router
$x = time
$X = date
$s = status
This variables are handled automatically by NNM and when running the command in converts them to the relevant value

Basically when I get the email(I get two emails sent per event)
In my inbox I get the output of the router that went down with the time an date and ping output all one line after the other (1st email). Then I get another email after that with the output of the same router that went down with the time an date and traceroute output 1 line after the other(2nd email)

I want to try and execute more commands in the script(I dont know wether to even call it a script because its a mess but it works) e.g a series of snmpget commands with the outputs on the email.
When I tried to play around with this I get the ping outputs mixed up with the snmpget commands, sometimes the subject header gets displaye in the body of the email, it just looks AWFUL,

e.g my ideal output

New-York router down at 17:00 on 07/05/02



and a few other more

Ping output:

(ping output)

Traceroute output:

(output of trace route)

Im not much of a scripter just learning.(please be kind with me and be as basic as possible).

regards,
gab
Jesus Christ is LORD
3 REPLIES 3
Seun Ewulomi_1
Honored Contributor

Re: scripting headache

Hi,

My apologies. I am running Solaris 2.6 with Hp openview Network Node manager. I send the emails using sendmail.
Il like to put all the commands into a shell script and ust have that file executed instead of typig all that into the automatic action command field in openview NNM.

Any help will be appreciated.

many thanks to harry d brown jr for helping and giving me a good start on this.
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xab75107d277ad611abdb0090277a778c,00.html


regards,
gab
Jesus Christ is LORD
Rich Wright
Trusted Contributor

Re: scripting headache

This would be my prefered method:
mailx -m -s "${subj_var} at ${time_var} on ${date_var}" ${sendto} << __EOM__
First line of message

Ping output:
$(ping blabla)

Following makes attachment of $tmp appearing as $name.txt
$(cat $tmp | ux2dos - | uuencode ${name}.txt)

Rest of message

__EOM__
Tom Maloy
Respected Contributor

Re: scripting headache

Stick the entire set of commands in a script, and redirect the script output to mailx:

gab.ksh | mailx -s "$A Router - Node Status $s at $x"

In the script gab.ksh:

#!/usr/bin/ksh

ROUTER=$1

#
# < link speed: (from the snmp get)>
# and a few other more
# insert those commands here

print "Ping output: "

ping -s $ROUTER 100 5

print "Traceroute output: "

/usr/bin/traceroute $ROUTER

# end of script

All of the script output will be sent (in the body of the message) via mailx.

Tom
Carpe diem!