The zd-mtx excitement continues...

I found that the script was getting confused when I had an amlabel which
was a substring of another amlabel. i.e. "Kiva2" and "Kiva22". When the
script grepped the amlabel out of the labelfile it was matching more than
one line.

My solution is just to use "grep -w" instead of "grep" in the appropriate
places. (In GNU grep the -w flag is "Select only those lines containing
matches that form whole words.")

My question is, does anyone have a grep in which the -w flag is
nonexistent or means something different? In which case the answer might
have to be "get GNU tools" because I can't think of any other solution I
really like. I can think of a couple but they're all gross hacks.

A "diff -uNr" is below.

Thanks,

        - A


---8<--cut--8<---

--- src/amanda/changer-src/chg-zd-mtx.sh.in     Sun Feb 25 20:34:15 2001
+++ chg-zd-mtx.sh.in    Fri Apr  6 16:12:22 2001
@@ -17,6 +17,11 @@
 # NOTE:  Only tested the 2 additions with an ADIC Scalar 100.
 # All my additions have a '#### Comment' close by.

+# Adrian Hosey <[EMAIL PROTECTED]>
+# Changed "grep" to "grep -w" whenever we're grepping in the
+# labelfile. Otherwise you can get problems when you have an amlabel
+# that is a substring of another amlabel.
+
 ################################################################################
 # NOTE: all variables are now placed in a 'changerfile'.conf in your
 # amanda config directory, where 'changerfile' is what's set in
@@ -364,12 +369,12 @@
                         echo "$tapelabel $barcode" > $labelfile
                         echo "0 $usedslot $tape"
                 else
-                        included=`grep $tapelabel $labelfile | awk '{print $1}'`
+                        included=`grep -w $tapelabel $labelfile | awk '{print $1}'`
                         if [ -z $included ]; then
                                 echo "$tapelabel $barcode" >> $labelfile
                                 echo "0 $usedslot $tape"
                         else
-                                oldbarcode=`grep $tapelabel $labelfile | awk '{print 
$2}'`
+                                oldbarcode=`grep -w $tapelabel $labelfile | awk 
+'{print $2}'`
                                 if [ $oldbarcode -eq $barcode ]; then
                                         echo "      -> Barcode $barcode $oldbarcode 
already synced for $tapelabel" >> $DBGFILE
                                         echo "0 $usedslot $tape"
@@ -397,8 +402,8 @@
 searchtape() {
         # readstatus
         tapelabel=$1
-        includedtag=`grep $tapelabel $labelfile | awk '{print $1}'`
-        includedbar=`grep $tapelabel $labelfile | awk '{print $2}'`
+        includedtag=`grep -w $tapelabel $labelfile | awk '{print $1}'`
+        includedbar=`grep -w $tapelabel $labelfile | awk '{print $2}'`
         tmpincludedslot=`$MTX status | grep $includedbar`
        includedslot=`echo $tmpincludedslot | sed -n "s/\(.*\)Storage Element 
\([1-9][0-9]*\):\(.*\)/\2/p;s/Data Transfer Element $drivenum:Full (Storage Element 
\([1-9][0-9]*\) Loaded)\(.*\)/\1/p"`
         case $tapelabel in


Reply via email to