1833861 Members
2475 Online
110063 Solutions
New Discussion

Script Help

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

Script Help

What does this mean in a script?

if [ "ping_status" ];
UNIX IS GOOD
9 REPLIES 9
baiju_3
Esteemed Contributor

Re: Script Help


Which Script was it , perl , ksh ,sh ?


Regards ..bl.
Good things Just Got better (Plz,not stolen from advertisement -:) )
Nobody's Hero
Valued Contributor

Re: Script Help

ksh
UNIX IS GOOD
Pete Randall
Outstanding Contributor

Re: Script Help

Robert,

I can't decipher the [, &#93. Did you cut and paste, by any chance or is that the way it appears in the script?


Pete

Pete
Geoff Wild
Honored Contributor

Re: Script Help

The [ is really the square intro bracket [ and the 93 ]

Cut 'n'paste issue in the forums...

if [ "ping_status" ];

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Chan 007
Honored Contributor

Re: Script Help

Provide the complete script, I guess there is a mistake/typo in what you have pasted..!!

Chan
Nobody's Hero
Valued Contributor

Re: Script Help

#! /bin/sh

host=`cat ipfile`
for item in $host
do
echo "Checking $host..."
ping_status=`ping $host 10|grep 'no answer'`
if [ "ping_status" ]; then
echo "$host NOT RESPONDING"
echo " "
continue
fi
echo "$host UP"
UNIX IS GOOD
Geoff Wild
Honored Contributor
Solution

Re: Script Help

Should be:

#! /bin/sh

host=`cat ipfile`
for item in $host
do
echo "Checking $host..."
ping_status=`ping $host 10|grep 'no answer'`
if [ "ping_status" ]; then
echo "$host NOT RESPONDING"
echo " "
continue
fi
echo "$host UP"

It is checking for a condition - if ping_status contains "no answer" then it will echo $host not responding.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sandman!
Honored Contributor

Re: Script Help

Robert,

The test part (if statement) is missing some constructs alongwith an else and done statements.

=============================================
#! /bin/sh

host=`cat ipfile`
for item in $host
do
echo "Checking $host..."
ping_status=`ping $host 10|grep 'no answer'`
if [ "$ping_status" ]; then
echo "$host NOT RESPONDING"
else
echo "$host UP"
fi
done
=============================================

cheers!
Geoff Wild
Honored Contributor

Re: Script Help

Just realized this is for solaris - your if statement should have -ne 0

#! /bin/sh

host=`cat ipfile`
for item in $host
do
echo "Checking $host..."
ping_status=`ping $host 10|grep 'no answer'`
if [ "ping_status" -ne 0 ]; then
echo "$host NOT RESPONDING"
echo " "
continue
fi
echo "$host UP"
done



Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.