From owner-freebsd-questions@FreeBSD.ORG Thu Apr 4 13:54:39 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 35CBE782 for ; Thu, 4 Apr 2013 13:54:39 +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 065B32D8 for ; Thu, 4 Apr 2013 13:54:38 +0000 (UTC) Received: from smtp.fisglobal.com ([10.132.206.16]) by ltcfislmsgpa03.fnfis.com (8.14.5/8.14.5) with ESMTP id r34DsWKY011537 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Thu, 4 Apr 2013 08:54:36 -0500 Received: from LTCFISWMSGMB21.FNFIS.com ([10.132.99.23]) by LTCFISWMSGHT05.FNFIS.com ([10.132.206.16]) with mapi id 14.02.0309.002; Thu, 4 Apr 2013 08:54:32 -0500 From: "Teske, Devin" To: Mark Felder Subject: Re: OT: posix sh problem Thread-Topic: OT: posix sh problem Thread-Index: AQHOMTCBUnKVZwodmkSvNRb8MTRBZJjGaUsA Date: Thu, 4 Apr 2013 13:54:30 +0000 Message-ID: <13CA24D6AB415D428143D44749F57D7201EF2411@ltcfiswmsgmb21> References: 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: "" 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 13:54:39 -0000 On Apr 4, 2013, at 5:32 AM, Mark Felder wrote: > Hi all, >=20 > Hopefully someone here is much more clever than I am. I've run out of ide= as on how to cleanly convert this chunk of ksh to posix sh. /me takes the challenge (and shame on some of the current responses; this i= s trivial in sh and there's actually nothing wrong with the OPs code -- it = works) > This is from a BB/Hobbit/Xymon monitoring script for ZFS. I'd really like= to have this working cleanly on FreeBSD without requiring any funky shells= or using any temporary files. >=20 Cool! After I help you fix whatever the issue is, I'd be interested in this= a little more. ZFS monitoring would be nice. > The following is supposed to be able to loop through the output of multip= le zpools reading one line at a time and each line item is set as a variabl= e: >=20 >=20 > /sbin/zpool list -H | while read name size used avail cap dedup health al= troot > do > # do interesting things here > done >=20 > Unfortunately you can't pipe through read in posix sh. Wait, you can't? Then I've been doing something wrong all these years=85 #!/bin/sh printf "line1\nline2\n" | while read line do echo "line=3D[$line]" done =3D=3D=3D dteske@scribe9.vicor.com ~ $ sh bar line=3D[line1] line=3D[line2] =3D=3D=3D Just a side note, on my "zpool list -H" on my 8.1-R system doesn't provide = the "dedup" column, so your mileage may vary (you may have to adjust the sc= ript to account for that on systems like mine). Aside from that, I took your script as-is, copy/paste and it worked fine on= 8.1-RELEASE-p6: dteske@oos0a.lbxrich.vicor.com ~ $ cat bar #!/bin/sh /sbin/zpool list -H | while read name size used avail cap dedup health altr= oot do echo $name done dteske@oos0a.lbxrich.vicor.com ~ $ sh bar NEC1-RAID6-ARRAY1 NEC1-RAID6-ARRAY2 NEC1-RAID6-ARRAY3 > You also can't use process substitution: while read var1 var1 < <(/sbin/z= pool list -H) >=20 I'll admit that one's unsupported. > Any ideas are greatly appreciated. I know there's a python-based script f= loating on github but I cant guarantee every server will have python on it= =85 >=20 Stick to /bin/sh if you can (like you say, portability and potability in us= ing base utilities). > Source of script is here: http://en.wikibooks.org/wiki/System_Monitoring_= with_Xymon/Other_Docs/HOWTO#Hobbit_Client_and_ZFS_monitoring The only things I saw that needed changing to go from ksh to /bin/sh were: 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 nestab= le $(=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-lin= e tool and not a BB/Hobbit/Xymon module. --=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.