Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Apr 2013 16:16:11 +0000
From:      "Teske, Devin" <Devin.Teske@fisglobal.com>
To:        Mark Felder <feld@feld.me>
Cc:        Devin Teske <dteske@freebsd.org>, "<freebsd-questions@freebsd.org>" <freebsd-questions@freebsd.org>
Subject:   Re: OT: posix sh problem
Message-ID:  <13CA24D6AB415D428143D44749F57D7201EF27F3@ltcfiswmsgmb21>
In-Reply-To: <op.wu0u5lpq34t2sn@tech304.office.supranet.net>
References:  <op.wu0nsgsf34t2sn@tech304.office.supranet.net> <13CA24D6AB415D428143D44749F57D7201EF2411@ltcfiswmsgmb21> <op.wu0u5lpq34t2sn@tech304.office.supranet.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On Apr 4, 2013, at 8:11 AM, Mark Felder wrote:

> Sorry, my email client did something weird with collapsing and I didn't s=
ee you mention that it appeared to be working for you.
>=20
> On Thu, 04 Apr 2013 08:54:30 -0500, Teske, Devin <Devin.Teske@fisglobal.c=
om> wrote:
>=20
>> The only things I saw that needed changing to go from ksh to /bin/sh wer=
e:
>> 	if [ =85 =3D=3D =85 ]; then
>> Needs to be
>> 	if [ =85 =3D =85 ]; then
>> And optionally, a style nit would be to convert back-tick pairs into nes=
table $(=85) syntax. For example, change:
>> 	cap=3D`=85`
>> to instead:
>> 	cap=3D$(=85)
>> Oh and of course, the HTML should go away since you're making a command-=
line tool and not a BB/Hobbit/Xymon module.
>=20
> I actually will be using this with Xymon at work. I did fix the =3D=3D an=
d style nit when I went over this script I'm still having a problem.

No worries=85


> When I started debugging this last night $STRING led me to believe the pi=
pe into read wasn't working right. At the bottom of the script I added echo=
 in front of the "$BB $BBDISP...." line.

Ok, going back to the original script, I see the error.

Yes=85 you're right, you can't modify a string from the rvalue of a pipe; s=
imply put.


[snip]

> Do you see what I mean now? :(

Yes, I do.

Here's what I suggest (the following works for me -- lists all my pools and=
 shows healthy):

--- bar.orig	2013-04-04 09:05:27.000000000 -0700
+++ bar	2013-04-04 09:14:37.000000000 -0700
@@ -1,4 +1,5 @@
-#!/bin/ksh
+#!/bin/sh
+BB=3Decho MACHINE=3D$(hostname)
 # Revision History:=20
 # 1. Mike Rowell <Mike.Rowell@Rightmove.co.uk>, original
 # 2. Uwe Kirbach <U.Kirbach@EnBW.com>
@@ -22,19 +23,20 @@ STRING=3D"<table border=3D0 cellpadding=3D10><
 # mypool  33.8G   84.5K   33.7G   0%      ONLINE  -
 # bash-3.00#
=20=20
-/usr/sbin/zpool list -H | while read name size used avail cap health altro=
ot
+STRING=3D"$STRING$(
+/sbin/zpool list -H | while read name size used avail cap health altroot
 do
   LINE_COLOR=3D"green"
=20=20
-  if [ "${health}" =3D=3D "ONLINE" ]; then
+  if [ "${health}" =3D "ONLINE" ]; then
     HEALTH_COLOR=3D"green"
-  elif [ "${health}" =3D=3D "DEGRADED" ]; then
+  elif [ "${health}" =3D "DEGRADED" ]; then
     HEALTH_COLOR=3D"yellow"
-  elif [ "${health}" =3D=3D "FAULTED" ]; then
+  elif [ "${health}" =3D "FAULTED" ]; then
     HEALTH_COLOR=3D"red"
   fi=20
=20=20
-  cap=3D`echo ${cap} | cut -d% -f1`=20
+  cap=3D$(echo ${cap} | cut -d% -f1)=20
   if [ ${cap} -lt $DISKYELL ]; then
     CAP_COLOR=3D"green"=20
   elif [ ${cap} -gt $DISKYELL ]; then=20
@@ -43,7 +45,7 @@ do
     CAP_COLOR=3D"red"
   fi
=20=20
-  if [ "$HEALTH_COLOR" =3D=3D "red" -o "$HEALTH_COLOR" =3D=3D "yellow" -o =
"$CAP_COLOR" =3D=3D "red" -o "$CAP_COLOR" =3D=3D "yellow" ]; then
+  if [ "$HEALTH_COLOR" =3D "red" -o "$HEALTH_COLOR" =3D "yellow" -o "$CAP_=
COLOR" =3D "red" -o "$CAP_COLOR" =3D "yellow" ]; then
     DISPCOLOR=3D$COLOR
     LINE_COLOR=3D$COLOR
   fi
@@ -58,13 +60,14 @@ do
     yellow) FIRST_LINE_CAP=3D"nearly full" ;;
   esac
=20=20
-  STRING=3D"$STRING <tr><td>&${LINE_COLOR}</td><td>${name}</td><td>${healt=
h}</td><td>${cap}</td></tr>"
+  echo "<tr><td>&${LINE_COLOR}</td><td>${name}</td><td>${health}</td><td>$=
{cap}</td></tr>"
 done
+)"
=20=20
 # What: accumulate the bb message strings.
 STRING=3D"$STRING </table><br><br>"
-STRING=3D"$STRING`/usr/sbin/zpool status -xv`"
+STRING=3D"$STRING$(/sbin/zpool status -xv)"
 FIRST_LINE=3D"zfs - health: $FIRST_LINE_HEALTH - capacity: $FIRST_LINE_CAP"
=20=20
 # What: Sent out the final bb message to hobbit server.
-$BB $BBDISP "status $MACHINE.$TEST $DISPCOLOR `date` $FIRST_LINE $STRING"
+$BB $BBDISP "status $MACHINE.$TEST $DISPCOLOR $(date) $FIRST_LINE $STRING"

--=20
Devin

_____________
The information contained in this message is proprietary and/or confidentia=
l. If you are not the intended recipient, please: (i) delete the message an=
d all copies; (ii) do not disclose, distribute or use the message in any ma=
nner; and (iii) notify the sender immediately. In addition, please be aware=
 that any message addressed to our domain is subject to archiving and revie=
w by persons other than the intended recipient. Thank you.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?13CA24D6AB415D428143D44749F57D7201EF27F3>