Operating System - HP-UX
1848279 Members
2111 Online
104023 Solutions
New Discussion

A korn shell Script for test up/down nodes

 
SOLVED
Go to solution
Bitraptor
Occasional Advisor

A korn shell Script for test up/down nodes

I need to develop, test, and implement a utility for polling all computing devices via ICMP Ping and alerting via OVO for nodes which do not respond and write it to a file so that OVO may read and generate an alert.(Opcnode command).I've already developed and tested one that i have, but i need to optimize it. The script is the following

#!/usr/bin/ksh
##################################################
#
# Check status of OVO agent - Ping Test Only
#
##################################################

INFILE=$1

if [[ -z $1 || ! -f $1 ]]; then
echo "Pls specify a valid input filename"
exit 9
fi

OUTFILE=/home/aa6491/agent_ping_test.out
OUTFILE2=/home/aa6491/agent_ping_test.rpt

/momauto/managers/OV/log #this is the right path where the files should be written to.

> $OUTFILE
> $OUTFILE2

Total_Nodes=`wc -l $INFILE | awk '{print $1}'`
Node_Num=0

echo `date +"%x %X"` "Node PING test started for $Total_Nodes configured nodes"

for nodename in `cat $INFILE`; do
(( Node_Num = $Node_Num + 1 ))
ping $nodename -n 1 >/dev/null 2>/dev/null
RC=$?
if [[ $RC -ne 0 ]]; then
echo `date +"%x %X"` "$nodename:Agent $Node_Num of $Total_Nodes, did not respond to ICMP ping" | tee -a $OUTFILE2
else
echo `date +"%x %X"` "$nodename:Agent $Node_Num of $Total_Nodes, did respond to ICMP ping" | tee -a $OUTFILE2
fi
done

echo `date +"%x %X"` "Node PING test complete"

exit 0


Do you guys have any other suggestions on how i should be modifying and implementing new features to this script? Do you have any other new script suggestion for this case? It's URGENT. I would appreciate any help. Thanks.
13 REPLIES 13
Steven Schweda
Honored Contributor

Re: A korn shell Script for test up/down nodes

I give up. What's "URGENT"? Why do you wish
to change the script you have? What new
features do you want? For what kinds of
suggestions are you looking?
Dennis Handly
Acclaimed Contributor
Solution

Re: A korn shell Script for test up/down nodes

Only a few trivial changes:
Total_Nodes=$(wc -l < $INFILE)

And replace archaic `` by $() throughout.

You don't need the "$" in (( )):
(( Node_Num = $Node_Num + 1 ))

No need for cat:
for nodename in $(< $INFILE); do

You set $INFILE at the top. You then check $1, you should be consistent and use $INFILE. And in your error message, you should echo $INFILE so the error is reinforced by the bad name.
Steven Schweda
Honored Contributor

Re: A korn shell Script for test up/down nodes

If I had to _use_ this script, my first
complaint might be that it does not allow the
input file to include any comments, which is
bad for at least two reasons. (Or blank
lines?)
Bitraptor
Occasional Advisor

Re: A korn shell Script for test up/down nodes



Hi Dennis

Thank you very much for your help. I could ask you only one more thing. How ecxatly would you build this script having mine as an example? I mean, could you write it down throughout with your considerable optimizations? If there will be some explanation on the optimization i would be glad, it's been quite a whil i haven't ben into korn shell script. I'll implement this in the next few weeks in a very large enviroment for a HP client. Thank you one more time Dennis and i wait for your feedback.
Steven Schweda
Honored Contributor

Re: A korn shell Script for test up/down nodes

Do I have this right? You have a paying
client, you don't know how to do the job, and
you can't even implement the suggestions you
already have, so you want someone else to do
your whole job for you for free (or for a few
ITRC points)? Or do I misunderstand?

Perhaps you should hire a (sub-) contractor
who _does_ know how to do your job. (But,
hey, if you can get someone to do your job
for nothing, it's ok with me.)
Dennis Handly
Acclaimed Contributor

Re: A korn shell Script for test up/down nodes

>How exactly would you build this script having mine as an example?

Well, yours seems to do what it says. (I don't see any use of $OUTFILE.)

You do know that just because you can ping a system doesn't mean it isn't hung?
Bitraptor
Occasional Advisor

Re: A korn shell Script for test up/down nodes



I won't use the $OUTFILE just the $OUTFILE2.

I tried to made those changes you sent to me but didn't worked it out. The script got an error.When i put the script back, it worked.
Dennis Handly
Acclaimed Contributor

Re: A korn shell Script for test up/down nodes

>I tried to made those changes you sent to me but didn't worked it out. The script got an error.

Can you attach your script so I can look at the error? And provide error message.
Bitraptor
Occasional Advisor

Re: A korn shell Script for test up/down nodes


Hi Dennis,

I'm sending you the file attached. See what you can get from it. If you make any modifications and or get it optimized, let me know.


Thanks.
Dennis Handly
Acclaimed Contributor

Re: A korn shell Script for test up/down nodes

>If you make any modifications and or get it optimized, let me know.

I changed:
Total_Nodes=$(wc -l < $INFILE)
for nodename in $(< $INFILE); do

(Note this will allow multiple hosts on one line but your wc won't count them. You could change to wc -w.)

Each line with `date` to:
echo $(date +"%x %X") ...

There were two lines with: | >> $OUTFILE2

I assumed you didn't remove the tee completely?

echo $(date +"%x %X") "$nodename:Agent $Node_Num of $Total_Nodes, did not respond to ICMP ping" >> $OUTFILE2
Bitraptor
Occasional Advisor

Re: A korn shell Script for test up/down nodes


Yes, i didn't remove the "tee" for the "$OUTFILE" just to see the testing results on the screen in real time.I'll be doing this when i implemtent the script in the production enviroment. The 2 lines containing >>OUFILE2 are for diffrent purposes if haven't pay enough atention:

if [[ $RC -ne 0 ]]; then
echo `date +"%x %X"` "$nodename:Agent $Node_Num of $Total_Nodes, did not respond to ICMP ping" | >> $OUTFILE2
else
echo `date +"%x %X"` "$nodename:Agent $Node_Num of $Total_Nodes, did respond to ICMP ping" | >> $OUTFILE2
fi
done

----- one is for the nodes which responds and other wich doesn't. -------

- Look , i tried to make those changes you made and as i stated before in the last post, for some readon it didn't work out.

could you send the attached file with the changes you made on it for me be able to test it out?!

ThX
Bitraptor
Occasional Advisor

Re: A korn shell Script for test up/down nodes



Yes, i didn't remove the "tee" from the script yet for the the single reason i want to see the output on the screen in real time as the script runs,ok? This will be done later.

As for the changes you've made on the script for some reason it didn't work it out, as i stated in the last post, when i made those changes (Total_Nodes/ for nodename , etc)i got an error when the scritp ran.


Regarding the 2 ">>OUTFILES2" , they are for different purposes.One for the nodes wich reponde to the ping and the other for the ones wich do not,ok.


Could you attach a file with your changes so that i can test it out completly?

Thx.
Dennis Handly
Acclaimed Contributor

Re: A korn shell Script for test up/down nodes

>i didn't remove the "tee" from the script yet

They were only partially removed so it had bad syntax.

>Could you attach a file with your changes so that i can test it out completly?

Attached