OT: posix sh problem

Teske, Devin Devin.Teske at fisglobal.com
Thu Apr 4 16:16:16 UTC 2013


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

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

No worries…


> When I started debugging this last night $STRING led me to believe the pipe 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… you're right, you can't modify a string from the rvalue of a pipe; simply 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=echo MACHINE=$(hostname)
 # Revision History: 
 # 1. Mike Rowell <Mike.Rowell at Rightmove.co.uk>, original
 # 2. Uwe Kirbach <U.Kirbach at EnBW.com>
@@ -22,19 +23,20 @@ STRING="<table border=0 cellpadding=10><
 # mypool  33.8G   84.5K   33.7G   0%      ONLINE  -
 # bash-3.00#
  
-/usr/sbin/zpool list -H | while read name size used avail cap health altroot
+STRING="$STRING$(
+/sbin/zpool list -H | while read name size used avail cap health altroot
 do
   LINE_COLOR="green"
  
-  if [ "${health}" == "ONLINE" ]; then
+  if [ "${health}" = "ONLINE" ]; then
     HEALTH_COLOR="green"
-  elif [ "${health}" == "DEGRADED" ]; then
+  elif [ "${health}" = "DEGRADED" ]; then
     HEALTH_COLOR="yellow"
-  elif [ "${health}" == "FAULTED" ]; then
+  elif [ "${health}" = "FAULTED" ]; then
     HEALTH_COLOR="red"
   fi 
  
-  cap=`echo ${cap} | cut -d% -f1` 
+  cap=$(echo ${cap} | cut -d% -f1) 
   if [ ${cap} -lt $DISKYELL ]; then
     CAP_COLOR="green" 
   elif [ ${cap} -gt $DISKYELL ]; then 
@@ -43,7 +45,7 @@ do
     CAP_COLOR="red"
   fi
  
-  if [ "$HEALTH_COLOR" == "red" -o "$HEALTH_COLOR" == "yellow" -o "$CAP_COLOR" == "red" -o "$CAP_COLOR" == "yellow" ]; then
+  if [ "$HEALTH_COLOR" = "red" -o "$HEALTH_COLOR" = "yellow" -o "$CAP_COLOR" = "red" -o "$CAP_COLOR" = "yellow" ]; then
     DISPCOLOR=$COLOR
     LINE_COLOR=$COLOR
   fi
@@ -58,13 +60,14 @@ do
     yellow) FIRST_LINE_CAP="nearly full" ;;
   esac
  
-  STRING="$STRING <tr><td>&${LINE_COLOR}</td><td>${name}</td><td>${health}</td><td>${cap}</td></tr>"
+  echo "<tr><td>&${LINE_COLOR}</td><td>${name}</td><td>${health}</td><td>${cap}</td></tr>"
 done
+)"
  
 # What: accumulate the bb message strings.
 STRING="$STRING </table><br><br>"
-STRING="$STRING`/usr/sbin/zpool status -xv`"
+STRING="$STRING$(/sbin/zpool status -xv)"
 FIRST_LINE="zfs - health: $FIRST_LINE_HEALTH - capacity: $FIRST_LINE_CAP"
  
 # 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"

-- 
Devin

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


More information about the freebsd-questions mailing list