ADSM-L

Re: vaulting problem

2001-08-03 13:40:29
Subject: Re: vaulting problem
From: Alex Paschal <AlexPaschal AT FREIGHTLINER DOT COM>
Date: Fri, 3 Aug 2001 10:40:56 -0700
Here's a little bit of code to get you started.

Alex

#!/bin/ksh
#
#   This is a simple script to process vault slotting for ADSM DR Media
#   The slot file has to be generated first, and looks something like
#
#   A001   -Empty
#   A002   -Empty
#
#

#set -x

function usage {
   print
   print "usage:  vault [-r|-v] file1 file2"
   print "usage:  vault [-o|-e] file2"
   print "usage:  vault [-s] string file2"
   print
   print -- "-r     return from vault"
   print -- "-v     send to vault"
   print -- "-o     print contents of slots"
   print -- "-c     free slot count"
   print -- "-s     search slots for a string"
   print -- "-e     edit the slot list"
   print "string search string"
   print "file1  filename of the list of tapes to send or return"
   print "file2  filename of the list of slots"
}

function unslot_tapes {
   tapes=$1
   slots=$2
   grep -f $tapes $slots | awk '{print $1" -Empty"}' > slots.empty
   grep -vf $tapes $slots > slots.unchanged
   cat slots.empty >> slots.unchanged
   awk '{print $1}' slots.empty > tmp3.$$
   grep -f tmp3.$$ $slots
   rm tmp3.$$
   sort +0 -1 slots.unchanged > $slots
   rm slots.unchanged
}

function slot_tapes {
   tapes=$1
   slots=$2
   grep -f $tapes $slots > slots.vaulted
   awk '{print $2}' slots.vaulted > tmp.$$
   grep -vf tmp.$$ $tapes > tapes.2
   grep -vf tmp.$$ $slots > tmp2.$$
   cat tmp2.$$ > $slots
   rm tmp2.$$
   rm tmp.$$
   exec 3< tapes.2
   grep "\-Empty" $slots | awk '{print $1}' | while read slotnum; do
      if read -u3 volume; then
         print "$slotnum $volume "`date +"%m/%d/%y"` >> slots.vaulted
      else
         break;
      fi
   done
   awk '{print $1}' slots.vaulted > tmp.$$
   grep -vf tmp.$$ $slots > slots.unchanged
   rm tmp.$$
   cat slots.vaulted >> slots.unchanged
   sort +0 -1 slots.unchanged > $slots
   rm tapes.2 slots.unchanged
   cat slots.vaulted
}

if [[ ! $# -gt 1 ]]; then
   usage
   return 1
elif [[ $1 = "-c" ]]; then
   if [[ ! -s $2 ]]; then print "unable to open file $2"; return 1; fi
   grep -c "\-Empty" $2
elif [[ $1 = "-o" ]]; then
   if [[ ! -s $2 ]]; then print "unable to open file $2"; return 1; fi
   grep -v "\-Empty" $2 2>/dev/null
elif [[ $1 = "-e" ]]; then
   if [[ ! -s $2 ]]; then print "unable to open file $2"; return 1; fi
   vi $2
elif [[ ! $# -eq 3 ]]; then
   usage
   return 1
elif [[ $1 = "-s" ]]; then
   if [[ ! -s $3 ]]; then print "unable to open file $3"; return 1; fi
   grep $2 $3 2>/dev/null
   if [[ ! $? -eq 0 ]]; then
      print "Unable to find pattern"
      return 1
   fi
elif [[ ! ( -s $2 && -s $3 ) ]]; then
   print "one of the files, $2 or $3, doesn\'t exist."
   return 1
elif [[ $1 = "-r" ]]; then
   unslot_tapes $2 $3
elif [[ $1 = "-v" ]]; then
   slot_tapes $2 $3
fi

<Prev in Thread] Current Thread [Next in Thread>