Love, Robert W wrote:
> Joe Eykholt wrote:
>> Robert Love wrote:
>>> On Mon, 2009-04-13 at 15:20 -0700, Joe Eykholt wrote:
>>>> Robert Love wrote:
>>> <snip>
>>>> BTW, you could use grep -q instead of grep -c.
>>>>
>>>> Instead of:
>>>>
>>>>    if [ `dcbtool gc ${IFNAME} app:0 | grep Enable | grep -c true` -ne
>>>> 1 ] ; then 
>>>>
>>>> do:
>>>>    if dcbtool gc ${IFNAME} app:0 | grep Enable | grep -q true ; then
>>>> : ; else           echo ... 
>>>>
>>>> To further simplify (but possibly obscure):
>>>>
>>>>    dcbtool gc ${IFNAME} app:0 | grep Enable | grep -q true || echo
>>>> "not enabled ..." 
>>>>
>>> I started coding this, but I don't think that I like it. This is the
>>> DCB check, not app:0, but it's the syntax we're talking about. I end
>>> up with- 
>>>
>>> dcbtool gc ${IFNAME} dcb | grep 'DCB State' | grep -q on ||
>>> ( echo "DCB is not on, exectue the following command to turn it on"
>>>     >&2 && echo "dcbtool sc ${IFNAME} dcb on" >&2 &&
>>>     failure=1 )
>>>
>>> (the line wrap is making this look a bit funky, the "&&" on line #3
>>> should really be at the end of line #2)
>>>
>>> I don't think the shortcut use makes it any more readable since I
>>> really want to do 3 things on the failure of my dcbtool output
>>> greppping. 
>> Also, setting failure=1 in a subshell (in the parens) doesn't change
>> the value in the parent shell, so that won't work.
>>
>> How about:
>>
>>      dcbtool gc ${IFNAME} dcb | grep 'DCB State' | grep -q on
>>      if [ $? -ne 0 ]
>>      then
>>              echo "DCB is not on, exectue the following command to turn it 
>> on"
>>              >&2 echo "dcbtool sc ${IFNAME} dcb on" >&2
>>              failure=1
>>      fi
>>
>> Regards,
>>      Joe
> 
> Why run dcbtool/grep and then evaluate it's return value separately instead of
> in the if [] condition itself?
> 
> Right now I've got-
> 
> # Determine if DCB is on                                                      
>                    
> if dcbtool gc ${IFNAME} dcb | grep 'DCB State' | grep -q off ; then
>     echo "DCB is not on, exectue the following command to turn it on" >&2
>     echo "dcbtool sc ${IFNAME} dcb on" >&2
>     ret=1
> fi

Because we want the opposite, and I couldn't figure out how to invert the
return code neatly.  Maybe use grep -v?
My initial attempt did nothing in the then portion
and did the rest of the work in the else.

        Joe

_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to