Xymon Mailing List Archive search

if statment issue on ext script

11 messages in this thread

list Usa Ims · Wed, 24 Sep 2014 12:54:44 -0700 ·
Hi,

if statement not working in my ext script. Once the script is executed, the hostname is not showing
up in the MSG statement -- do you see anything obvious? I needed to 'x' out the ipaddress so my boss 
won't have a security panic attack.

 $BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do
  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then

        
if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then
HOST=`echo "server33.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then
HOST=`echo "server34.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then
HOST=`echo "server35.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then
HOST=`echo "server36.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then
HOST=`echo "server37.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then
HOST=`echo "server38.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then
HOST=`echo "server39.misc.corp.local"`
fi

####
MSG="
XYMON MESSAGE
SERVER : "$HOST" ## printing blank here
IPADDRESS : $IP  ## ipaddress is echoing fine.
"

$BB $BBDISP "status $HOSTNAME.$TESTNAME $COL
$MSG"
list Glauber Ribeiro · Wed, 24 Sep 2014 20:49:31 +0000 ·
Why all the "echo"s? :-) they don't seem to be adding anything to just having the variable there.

But anyway, I think the problem is that your first double quote in the "HOST" line is ending your MSG string.

g
quoted from Usa Ims

-----Original Message-----
From: usa ims [mailto:user-42bb6445007b@xymon.invalid] 
Sent: Wednesday, September 24, 2014 14:55
To: xymon at xymon.com
Subject: if statment issue on ext script

Hi,

if statement not working in my ext script. Once the script is executed, the hostname is not showing
up in the MSG statement -- do you see anything obvious? I needed to 'x' out the ipaddress so my boss 
won't have a security panic attack.

 $BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do
  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then

        
if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then
HOST=`echo "server33.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then
HOST=`echo "server34.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then
HOST=`echo "server35.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then
HOST=`echo "server36.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then
HOST=`echo "server37.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then
HOST=`echo "server38.misc.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then
HOST=`echo "server39.misc.corp.local"`
fi

####
MSG="
XYMON MESSAGE
SERVER : "$HOST" ## printing blank here
IPADDRESS : $IP  ## ipaddress is echoing fine.
"

$BB $BBDISP "status $HOSTNAME.$TESTNAME $COL
$MSG"
list Usa Ims · Wed, 24 Sep 2014 14:55:21 -0700 ·
The MSG still prints, here is what is printing. The server name is missing.

XYMON MESSAGE
            DATACENTER : D1
            SERVER : 
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT

On Wed, 9/24/14, Ribeiro, Glauber <user-59d088777028@xymon.invalid> wrote:

 Subject: RE: if statment issue on ext script
 To: "usa ims" <user-42bb6445007b@xymon.invalid>, "xymon at xymon.com" <xymon at xymon.com>
 Date: Wednesday, September 24, 2014, 4:49 PM
quoted from Glauber Ribeiro
 
 Why all the
 "echo"s? :-) they don't seem to be adding
 anything to just having the variable there.
 
 But anyway, I think the
 problem is that your first double quote in the
 "HOST" line is ending your MSG string.
 
 g
 
 -----Original Message-----
 From: usa ims [mailto:user-42bb6445007b@xymon.invalid]
 
 Sent: Wednesday, September 24, 2014
 14:55
 To: xymon at xymon.com
 Subject: if statment issue on ext script
 
 Hi,
 
 if statement not working in my ext script. Once
 the script is executed, the hostname is not showing
 up in the MSG statement -- do you see anything
 obvious? I needed to 'x' out the ipaddress so my
 boss 
 won't have a security panic
 attack.
 
 
 $BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME
 OTHER; do
   if do_fetch $HOSTNAME $IP |
 grep "$REGEX" > /dev/null ; then
 
         
 if [[ `echo "$IP"` =~
 ^10.xxx.xxx.1[0-9] ]]; then
 HOST=`echo
 "server33.misc.corp.local"`
 
 elif [[ `echo "$IP"` =~
 ^10.xxx.xxx.2[0-9] ]]; then
 HOST=`echo
 "server34.misc.corp.local"`
 
 elif [[ `echo "$IP"` =~
 ^10.xxx.xxx.3[0-9] ]]; then
 HOST=`echo
 "server35.misc.corp.local"`
 
 elif [[ `echo "$IP"` =~
 ^10.xxx.xxx.4[0-9] ]]; then
 HOST=`echo
 "server36.misc.corp.local"`
 
 elif [[ `echo "$IP"` =~
 ^10.xxx.xxx.5[0-9] ]]; then
 HOST=`echo
 "server37.misc.corp.local"`
 
 elif [[ `echo "$IP"` =~
 ^10.xxx.xxx.6[0-9] ]]; then
 HOST=`echo
 "server38.misc.corp.local"`
 
 elif [[ `echo "$IP"` =~
 ^10.xxx.xxx.7[0-9] ]]; then
 HOST=`echo
 "server39.misc.corp.local"`
 fi
 
 ####
 MSG="
 XYMON MESSAGE
 SERVER :
 "$HOST" ## printing blank here
 IPADDRESS : $IP  ## ipaddress is echoing
 fine.
 "
 
 $BB $BBDISP "status $HOSTNAME.$TESTNAME
 $COL
 $MSG"
list James Louis · Thu, 25 Sep 2014 08:06:12 -0500 ·
quoted from Usa Ims
On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com> wrote:
XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT
Why is there more to your MSG than what is in your script?

Jim


-- 


*     Jim Louis       \\\\||////       \ ~ ~  /       | @ @ |*


*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
list Rodney Simioni · Thu, 25 Sep 2014 13:20:25 +0000 ·
Sorry about that.
The issue is that $HOST is not printed in the output next to SERVER.
quoted from Usa Ims

$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do
  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then

HOST=`echo "server33.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then
HOST=`echo "server34.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then
HOST=`echo "server35.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then
HOST=`echo "server36.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then
HOST=`echo "server37.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then
HOST=`echo "server38.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then
HOST=`echo "server39.test.corp.local"`
fi

if [ $(echo "$X < 10" | bc) -ne 0 ]; then
            COL=green
            MSG="
            BIG BROTHER MESSAGE
            DATACENTER : D1
            SERVER : "$HOST"
            STATE : Normal
            STATUS : Green
            TEST : TestProd EchoTest
            RESPONSE SUCCEEDED : "$X" sec
            IP : "$IP"
            EVENT TIME : `date +"%c"`

            "

           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL
           $MSG"
#########################
Here is the output – notice that server is empty:
quoted from James Louis

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of James Louis
Sent: Thursday, September 25, 2014 9:06 AM
To: usa ims
Cc: xymon at xymon.com
Subject: Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com<mailto:xymon at xymon.com>> wrote:
XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT

Why is there more to your MSG than what is in your script?
Jim


--

     Jim Louis

       \\\\||////
       \ ~ ~  /
       | @ @ |
--oOo---(_)---oOo--

"If a free society cannot help the many who are poor, it cannot save the few who are rich." ~ John Kennedy
list James Louis · Thu, 25 Sep 2014 08:32:26 -0500 ·
Just for test purposes can you add a line like "TESTWORD=`echo myTestWord`"
in each if statement and then add a line to the msg like "TESTWORD :
$TESTWORD" and then run it again.

Thanks,
Jim

On Thu, Sep 25, 2014 at 8:20 AM, Simioni, Rodney <user-3ffedc1f4d0c@xymon.invalid>
quoted from Rodney Simioni
wrote:
 Sorry about that.

The issue is that $HOST is not printed in the output next to SERVER.


$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do

  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then

HOST=`echo "server33.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then

HOST=`echo "server34.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then

HOST=`echo "server35.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then

HOST=`echo "server36.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then

HOST=`echo "server37.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then

HOST=`echo "server38.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then

HOST=`echo "server39.test.corp.local"`

fi


if [ $(echo "$X < 10" | bc) -ne 0 ]; then

            COL=green

            MSG="

            BIG BROTHER MESSAGE


            DATACENTER : D1

            SERVER : "$HOST"

            STATE : Normal

            STATUS : Green

            TEST : TestProd EchoTest

            RESPONSE SUCCEEDED : "$X" sec

            IP : "$IP"

            EVENT TIME : `date +"%c"`


            "


           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL

           $MSG"

#########################

Here is the output – notice that server is empty:


XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


*From:* Xymon [mailto:xymon-bounces at xymon.com] *On Behalf Of *James Louis
*Sent:* Thursday, September 25, 2014 9:06 AM
*To:* usa ims
*Cc:* xymon at xymon.com
*Subject:* Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com>
wrote:

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


Why is there more to your MSG than what is in your script?

Jim


--


*     Jim Louis        \\\\||////        \ ~ ~  /        | @ @ |*

*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
-- 


*     Jim Louis       \\\\||////       \ ~ ~  /       | @ @ |*


*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
list Steve Coile · Thu, 25 Sep 2014 10:08:46 -0400 ·
Rodney, your script is broken on many levels.

   - The code you provided is incomplete: the *while* loop has a *do*, but
   no *done*, and the outer-most *if* has a *then* but no *fi*.


   - It isn't clear what *do_fetch* does, nor what the *$REGEX* used to
   *grep* its output matches.


   - The use of *`echo "$IP"`* is excessive: *"$IP"* is sufficient.  For
   instance:

if [[ *`echo "$IP"`* =~ ^10.xxx.xxx.1[0-9] ]]; then


should be:

if [[ *"$IP"* =~ ^10.xxx.xxx.1[0-9] ]]; then


   - Your regular expressions in the *[[ ]]* expressions should be
   single-quoted, and the periods in the IP addresses should be escaped to
   they are matched literally, and not used as special characters.  For
   instance:

if [[ `echo "$IP"` =~ *^10.xxx.xxx.1[0-9]* ]]; then


should be:

if [[ "$IP" =~ *'^10\.xxx\.xxx\.1[0-9]$'* ]]; then


   - Your use of *echo* in your variable definitions is excessive; the
   literal string is sufficient.  For instance:

HOST=*`echo "server33.test.corp.local"`*


should be:

HOST=*'server33.test.corp.local'*


   - Your *if* statements attempting to identify $IP assume $IP will match
   one of the regular expressions.  What if it doesn't?  You should include
   some error handling, such as:

*else*

*echo "$IP: unrecognized address" >&2*

*exit 1*


   - It's not clear where *$X* comes from or what it represents.


   - The if statement testing *$X *is overly complex.

if [ *$(echo "$X < 10" | bc) -ne 0* ]; then


should be:

if [ *$X -lt 10* ]; then


   - The definition of *$MSG* contains unnecessary and potentially
   problematic quotes.
quoted from James Louis

MSG="

BIG BROTHER MESSAGE


DATACENTER : D1

SERVER : *"*$HOST*"*

STATE : Normal

STATUS : Green

TEST : TestProd EchoTest

RESPONSE SUCCEEDED : *"*$X*"* sec

IP : *"*$IP*"*

EVENT TIME : `date +"%c"`


"

should be:
quoted from James Louis

MSG="

BIG BROTHER MESSAGE


DATACENTER : D1

SERVER : $HOST

STATE : Normal

STATUS : Green

TEST : TestProd EchoTest

RESPONSE SUCCEEDED : $X sec

IP : $IP

EVENT TIME : `date +"%c"`


"


-- 

*Steve Coile*Senior Network and Systems Engineer, McClatchy Interactive
<http://www.mcclatchyinteractive.com/>;
Office: XXX-XXX-XXXX | Mobile: XXX-XXX-XXXX | Fax: XXX-XXX-XXXX
quoted from James Louis

On Thu, Sep 25, 2014 at 9:32 AM, James Louis <user-518fefde45bd@xymon.invalid> wrote:
Just for test purposes can you add a line like "TESTWORD=`echo
myTestWord`" in each if statement and then add a line to the msg like
"TESTWORD : $TESTWORD" and then run it again.

Thanks,
Jim

On Thu, Sep 25, 2014 at 8:20 AM, Simioni, Rodney <user-3ffedc1f4d0c@xymon.invalid>
wrote:
 Sorry about that.

The issue is that $HOST is not printed in the output next to SERVER.


$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do

  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then

HOST=`echo "server33.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then

HOST=`echo "server34.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then

HOST=`echo "server35.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then

HOST=`echo "server36.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then

HOST=`echo "server37.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then

HOST=`echo "server38.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then

HOST=`echo "server39.test.corp.local"`

fi


if [ $(echo "$X < 10" | bc) -ne 0 ]; then

            COL=green

            MSG="

            BIG BROTHER MESSAGE


            DATACENTER : D1

            SERVER : "$HOST"

            STATE : Normal

            STATUS : Green

            TEST : TestProd EchoTest

            RESPONSE SUCCEEDED : "$X" sec

            IP : "$IP"

            EVENT TIME : `date +"%c"`


            "


           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL

           $MSG"

#########################

Here is the output – notice that server is empty:


XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


*From:* Xymon [mailto:xymon-bounces at xymon.com] *On Behalf Of *James Louis
*Sent:* Thursday, September 25, 2014 9:06 AM
*To:* usa ims
*Cc:* xymon at xymon.com
*Subject:* Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com>
wrote:

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


Why is there more to your MSG than what is in your script?

Jim


--


*     Jim Louis        \\\\||////        \ ~ ~  /        | @ @ |*

*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
--


*     Jim Louis       \\\\||////       \ ~ ~  /       | @ @ |*


*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy

list Paul Root · Thu, 25 Sep 2014 14:27:31 +0000 ·
What’s with all the echos?  They are unnecessary and could be causing issues. The following works fine:

if [[ $IP =~ ^10.xxx.xxx.1[0-9]; then
     HOST=’server33.test.corp.local’
fi

$ IP=10.5.102.13
$ if [[ $IP =~ ^10.5.10[0-9].13 ]]; then
   echo "$IP is a match"
fi
10.5.102.13 is a match
$ if [[ $IP =~ ^10.5.102.1[0-9] ]]; then    echo "$IP is a match"; fi
10.5.102.13 is a match
$ if [[ $IP =~ ^10.5.102.2[0-9] ]]; then    echo "$IP is a match"; fi
quoted from Steve Coile


From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of Simioni, Rodney
Sent: Thursday, September 25, 2014 8:20 AM
To: James Louis; usa ims
Cc: xymon at xymon.com
Subject: Re: [Xymon] if statment issue on ext script

Sorry about that.
The issue is that $HOST is not printed in the output next to SERVER.

$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do
  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then
HOST=`echo "server33.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then
HOST=`echo "server34.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then
HOST=`echo "server35.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then
HOST=`echo "server36.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then
HOST=`echo "server37.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then
HOST=`echo "server38.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then
HOST=`echo "server39.test.corp.local"`
fi

if [ $(echo "$X < 10" | bc) -ne 0 ]; then
            COL=green
            MSG="
            BIG BROTHER MESSAGE
            DATACENTER : D1
            SERVER : "$HOST"
            STATE : Normal
            STATUS : Green
            TEST : TestProd EchoTest
            RESPONSE SUCCEEDED : "$X" sec
            IP : "$IP"
            EVENT TIME : `date +"%c"`

            "

           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL
           $MSG"
#########################
Here is the output – notice that server is empty:

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of James Louis
Sent: Thursday, September 25, 2014 9:06 AM
To: usa ims
Cc: xymon at xymon.com<mailto:xymon at xymon.com>
Subject: Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com<mailto:xymon at xymon.com>> wrote:
XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT

Why is there more to your MSG than what is in your script?
Jim


--

     Jim Louis

       \\\\||////
       \ ~ ~  /
       | @ @ |
--oOo---(_)---oOo--

"If a free society cannot help the many who are poor, it cannot save the few who are rich." ~ John Kennedy
list Rodney Simioni · Thu, 25 Sep 2014 14:49:54 +0000 ·
I have received many good tips which I will apply but let me finish James’s request. In the meantime, I will apply the recommendations and rerun the script.

I’ve added TESTWORD=`echo myTestWord`


if [[ `echo "$IP"`  =~ ^10.xxx.xx.1[0-9] ]]; then
HOST=`echo "server33.test.corp.local"`
TESTWORD=`echo myTestWord`

elif [[ `echo "$IP"` =~ ^10.xxx.xx.2[0-9] ]]; then
HOST=`echo "server34.test.corp.local"`
TESTWORD=`echo myTestWord`

elif [[ `echo "$IP"` =~ ^10.xxx.xx.3[0-9] ]]; then
HOST=`echo "server35.test.corp.local"`
TESTWORD=`echo myTestWord`

elif [[ `echo "$IP"` =~ ^10.xxx.xx.4[0-9] ]]; then
HOST=`echo "server36.test.corp.local"`
TESTWORD=`echo myTestWord`

elif [[ `echo "$IP"` =~ ^10.xxx.xx.5[0-9] ]]; then
HOST=`echo "server37.test.corp.local"`
TESTWORD=`echo myTestWord`

elif [[ `echo "$IP"` =~ ^10.xxx.xx.6[0-9] ]]; then
HOST=`echo "server38.test.corp.local"`
TESTWORD=`echo myTestWord`

elif [[ `echo "$IP"` =~ ^10.xxx.xx.7[0-9] ]]; then
HOST=`echo "server39.test.corp.local"`
TESTWORD=`echo myTestWord`
Fi

The output is:
BIG BROTHER MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : Prod EchoTest
            TESTWORD :
            RESPONSE SUCCEEDED : .059704341 sec
            IP : 10.218.161.11
            EVENT TIME : Thu 25 Sep 2014 10:44:59 AM EDT
quoted from James Louis


From: James Louis [mailto:user-518fefde45bd@xymon.invalid]
Sent: Thursday, September 25, 2014 9:32 AM
To: Simioni, Rodney
Cc: usa ims; xymon at xymon.com
Subject: Re: [Xymon] if statment issue on ext script

Just for test purposes can you add a line like "TESTWORD=`echo myTestWord`" in each if statement and then add a line to the msg like "TESTWORD : $TESTWORD" and then run it again.

Thanks,
Jim

On Thu, Sep 25, 2014 at 8:20 AM, Simioni, Rodney <user-3ffedc1f4d0c@xymon.invalid<mailto:user-3ffedc1f4d0c@xymon.invalid>> wrote:
Sorry about that.
The issue is that $HOST is not printed in the output next to SERVER.

$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do
  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then
HOST=`echo "server33.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then
HOST=`echo "server34.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then
HOST=`echo "server35.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then
HOST=`echo "server36.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then
HOST=`echo "server37.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then
HOST=`echo "server38.test.corp.local"`

elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then
HOST=`echo "server39.test.corp.local"`
fi

if [ $(echo "$X < 10" | bc) -ne 0 ]; then
            COL=green
            MSG="
            BIG BROTHER MESSAGE
            DATACENTER : D1
            SERVER : "$HOST"
            STATE : Normal
            STATUS : Green
            TEST : TestProd EchoTest
            RESPONSE SUCCEEDED : "$X" sec
            IP : "$IP"
            EVENT TIME : `date +"%c"`

            "

           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL
           $MSG"
#########################
Here is the output – notice that server is empty:

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


From: Xymon [mailto:xymon-bounces at xymon.com<mailto:xymon-bounces at xymon.com>] On Behalf Of James Louis
Sent: Thursday, September 25, 2014 9:06 AM
To: usa ims
Cc: xymon at xymon.com<mailto:xymon at xymon.com>
Subject: Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com<mailto:xymon at xymon.com>> wrote:
XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT

Why is there more to your MSG than what is in your script?
Jim


--

     Jim Louis

       \\\\||////
       \ ~ ~  /
       | @ @ |
--oOo---(_)---oOo--

"If a free society cannot help the many who are poor, it cannot save the few who are rich." ~ John Kennedy


--

     Jim Louis

       \\\\||////
       \ ~ ~  /
       | @ @ |
--oOo---(_)---oOo--

"If a free society cannot help the many who are poor, it cannot save the few who are rich." ~ John Kennedy
list James Louis · Thu, 25 Sep 2014 09:54:32 -0500 ·
His script works fine and he is looking for help in finding out why the one
variable doesn't expand. Once that is answered I'm sure he would be glad to
hear about other scripting advice.

Thanks,
Jim

On Thu, Sep 25, 2014 at 9:27 AM, Root, Paul T <user-76fdb6883669@xymon.invalid>
quoted from Rodney Simioni
wrote:
 What’s with all the echos?  They are unnecessary and could be causing
issues. The following works fine:


if [[ $IP =~ ^10.xxx.xxx.1[0-9]; then

     HOST=’server33.test.corp.local’

fi


$ IP=10.5.102.13

$ if [[ $IP =~ ^10.5.10[0-9].13 ]]; then
   echo "$IP is a match"
fi
10.5.102.13 is a match

$ if [[ $IP =~ ^10.5.102.1[0-9] ]]; then    echo "$IP is a match"; fi

10.5.102.13 is a match

$ if [[ $IP =~ ^10.5.102.2[0-9] ]]; then    echo "$IP is a match"; fi


*From:* Xymon [mailto:xymon-bounces at xymon.com] *On Behalf Of *Simioni,
Rodney
*Sent:* Thursday, September 25, 2014 8:20 AM
*To:* James Louis; usa ims
*Cc:* xymon at xymon.com
*Subject:* Re: [Xymon] if statment issue on ext script


Sorry about that.

The issue is that $HOST is not printed in the output next to SERVER.


$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do

  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then

HOST=`echo "server33.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then

HOST=`echo "server34.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then

HOST=`echo "server35.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then

HOST=`echo "server36.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then

HOST=`echo "server37.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then

HOST=`echo "server38.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then

HOST=`echo "server39.test.corp.local"`

fi


if [ $(echo "$X < 10" | bc) -ne 0 ]; then

            COL=green

            MSG="

            BIG BROTHER MESSAGE


            DATACENTER : D1

            SERVER : "$HOST"

            STATE : Normal

            STATUS : Green

            TEST : TestProd EchoTest

            RESPONSE SUCCEEDED : "$X" sec

            IP : "$IP"

            EVENT TIME : `date +"%c"`


            "


           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL

           $MSG"

#########################

Here is the output – notice that server is empty:


XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


*From:* Xymon [mailto:xymon-bounces at xymon.com <xymon-bounces at xymon.com>] *On
quoted from Rodney Simioni
Behalf Of *James Louis
*Sent:* Thursday, September 25, 2014 9:06 AM
*To:* usa ims
*Cc:* xymon at xymon.com
*Subject:* Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com>
wrote:

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


Why is there more to your MSG than what is in your script?

Jim


--


*     Jim Louis        \\\\||////        \ ~ ~  /        | @ @ |*

*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
-- 


*     Jim Louis       \\\\||////       \ ~ ~  /       | @ @ |*


*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
list Steve Coile · Thu, 25 Sep 2014 11:07:07 -0400 ·
It probably does expand, but it's never set because *$IP* never matches any
of the regular expressions.  An *else* statement with an error message will
show this.  Alternatively, in the definition of* $MSG*, give *$HOST* a
default value that makes this condition clear: *${HOST:-none}*.
signature


-- 

*Steve Coile*Senior Network and Systems Engineer, McClatchy Interactive
<http://www.mcclatchyinteractive.com/>;
Office: XXX-XXX-XXXX | Mobile: XXX-XXX-XXXX | Fax: XXX-XXX-XXXX

quoted from James Louis
On Thu, Sep 25, 2014 at 10:54 AM, James Louis <user-518fefde45bd@xymon.invalid> wrote:
His script works fine and he is looking for help in finding out why the
one variable doesn't expand. Once that is answered I'm sure he would be
glad to hear about other scripting advice.

Thanks,
Jim

On Thu, Sep 25, 2014 at 9:27 AM, Root, Paul T <user-76fdb6883669@xymon.invalid>
wrote:
 What’s with all the echos?  They are unnecessary and could be causing
issues. The following works fine:


if [[ $IP =~ ^10.xxx.xxx.1[0-9]; then

     HOST=’server33.test.corp.local’

fi


$ IP=10.5.102.13

$ if [[ $IP =~ ^10.5.10[0-9].13 ]]; then
   echo "$IP is a match"
fi
10.5.102.13 is a match

$ if [[ $IP =~ ^10.5.102.1[0-9] ]]; then    echo "$IP is a match"; fi

10.5.102.13 is a match

$ if [[ $IP =~ ^10.5.102.2[0-9] ]]; then    echo "$IP is a match"; fi


*From:* Xymon [mailto:xymon-bounces at xymon.com] *On Behalf Of *Simioni,
Rodney
*Sent:* Thursday, September 25, 2014 8:20 AM
*To:* James Louis; usa ims
*Cc:* xymon at xymon.com
*Subject:* Re: [Xymon] if statment issue on ext script


Sorry about that.

The issue is that $HOST is not printed in the output next to SERVER.


$BBHOME/bin/bbhostgrep $TESTNAME | while read IP HOSTNAME OTHER; do

  if do_fetch $HOSTNAME $IP | grep "$REGEX" > /dev/null ; then


if [[ `echo "$IP"` =~ ^10.xxx.xxx.1[0-9] ]]; then

HOST=`echo "server33.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.2[0-9] ]]; then

HOST=`echo "server34.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.3[0-9] ]]; then

HOST=`echo "server35.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.4[0-9] ]]; then

HOST=`echo "server36.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.5[0-9] ]]; then

HOST=`echo "server37.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.6[0-9] ]]; then

HOST=`echo "server38.test.corp.local"`


elif [[ `echo "$IP"` =~ ^10.xxx.xxx.7[0-9] ]]; then

HOST=`echo "server39.test.corp.local"`

fi


if [ $(echo "$X < 10" | bc) -ne 0 ]; then

            COL=green

            MSG="

            BIG BROTHER MESSAGE


            DATACENTER : D1

            SERVER : "$HOST"

            STATE : Normal

            STATUS : Green

            TEST : TestProd EchoTest

            RESPONSE SUCCEEDED : "$X" sec

            IP : "$IP"

            EVENT TIME : `date +"%c"`


            "


           $BB $BBDISP "status $HOSTNAME.$TESTNAME $COL

           $MSG"

#########################

Here is the output – notice that server is empty:


XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


*From:* Xymon [mailto:xymon-bounces at xymon.com <xymon-bounces at xymon.com>] *On
Behalf Of *James Louis
*Sent:* Thursday, September 25, 2014 9:06 AM
*To:* usa ims
*Cc:* xymon at xymon.com
*Subject:* Re: [Xymon] if statment issue on ext script


On Wed, Sep 24, 2014 at 4:55 PM, usa ims via Xymon <xymon at xymon.com>
wrote:

XYMON MESSAGE
            DATACENTER : D1
            SERVER :
            STATE : Normal
            STATUS : Green
            TEST : test
            RESPONSE SUCCEEDED : .079411876 sec
            IPADDRESS : 10.xxx.xxx.xxx
            EVENT TIME : Wed 24 Sep 2014 05:48:21 PM EDT


Why is there more to your MSG than what is in your script?

Jim


--


*     Jim Louis        \\\\||////        \ ~ ~  /        | @ @ |*

*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy
--


*     Jim Louis       \\\\||////       \ ~ ~  /       | @ @ |*


*--oOo---(_)---oOo--*

"If a free society cannot help the many who are poor, it cannot save the
few who are rich." ~ John Kennedy