From owner-freebsd-questions@FreeBSD.ORG Thu Apr 4 16:16:16 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 02BBF53B; Thu, 4 Apr 2013 16:16:16 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id C62F4E19; Thu, 4 Apr 2013 16:16:15 +0000 (UTC) Received: from smtp.fisglobal.com ([10.132.206.31]) by ltcfislmsgpa02.fnfis.com (8.14.5/8.14.5) with ESMTP id r34GGC3A018351 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Thu, 4 Apr 2013 11:16:12 -0500 Received: from LTCFISWMSGMB21.FNFIS.com ([10.132.99.23]) by LTCFISWMSGHT03.FNFIS.com ([10.132.206.31]) with mapi id 14.02.0309.002; Thu, 4 Apr 2013 11:16:12 -0500 From: "Teske, Devin" To: Mark Felder Subject: Re: OT: posix sh problem Thread-Topic: OT: posix sh problem Thread-Index: AQHOMTCBUnKVZwodmkSvNRb8MTRBZJjGaUsAgAAVioCAABIMgA== Date: Thu, 4 Apr 2013 16:16:11 +0000 Message-ID: <13CA24D6AB415D428143D44749F57D7201EF27F3@ltcfiswmsgmb21> References: <13CA24D6AB415D428143D44749F57D7201EF2411@ltcfiswmsgmb21> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.132.253.121] Content-Type: text/plain; charset="Windows-1252" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8626, 1.0.431, 0.0.0000 definitions=2013-04-04_06:2013-04-04,2013-04-04,1970-01-01 signatures=0 Cc: Devin Teske , "" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Devin Teske List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Apr 2013 16:16:16 -0000 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 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 , original # 2. Uwe Kirbach @@ -22,19 +23,20 @@ STRING=3D"< # 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 " + echo "" done +)" =20=20 # What: accumulate the bb message strings. STRING=3D"$STRING
&${LINE_COLOR}${name}${healt= h}${cap}
&${LINE_COLOR}${name}${health}$= {cap}


" -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.