OT: posix sh problem

Mark Felder feld at feld.me
Thu Apr 4 15:11:39 UTC 2013


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. 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. My output is this:

# sh zfs_xymon.sh
status .zfs green Thu Apr  4 09:59:36 CDT 2013 zfs - health: okay -  
capacity: okay <table border=0 cellpadding=10><tr><th></th><th>Zpool  
Name</th><th>Status</th><th>Capacity</th></tr> </table><br><br>all pools  
are healthy

Where are the other parts of the table showing each zpool? Those are just  
the headers. If you sh -x you'll see it flow like this:

+ read name size used avail cap depup health altroot
+ STRING='<table border=0 cellpadding=10><tr><th></th><th>Zpool  
Name</th><th>Status</th><th>Capacity</th></tr> </table><br><br>'
+ /sbin/zpool status -xv

It's like everything between do ... done never happened? If you put echo  
in front of line 60 you DO get output:

# sh zfs_xymon.sh
STRING=<table border=0 cellpadding=10><tr><th></th><th>Zpool  
Name</th><th>Status</th><th>Capacity</th></tr>  
<tr><td>&green</td><td>tank</td><td>ONLINE</td><td>48</td></tr>
status .zfs green Thu Apr  4 10:07:30 CDT 2013 zfs - health: okay -  
capacity: okay <table border=0 cellpadding=10><tr><th></th><th>Zpool  
Name</th><th>Status</th><th>Capacity</th></tr> </table><br><br>all pools  
are healthy

But as you can see, everything in that do ... done is disappearing.  
According to Rich's Posix sh tricks site it explains that the things to  
the right of that pipe are completed in a subprocess. The updates it makes  
to STRING never make it out so it can be used in the rest of the script.

Do you see what I mean now? :(


More information about the freebsd-questions mailing list