script assistance with shift J

Hey all, I need some assistance. I'm writing a script to eject tapes from a tape library, but the library is not a queued system and can only eject 15 tapes at a time.

I added paste -d : -s so that it goes through full_tapes and puts each media_id on one line separated by the :.

Now I'm stuck on how to I separate each set of 15 into multiple lines, if I have over 15 tapes. Otherwise, this works great if I only have to eject 15 tapes.

Here is what I have so far.

#!/usr/bin/ksh

#################################
# DEFINE FILES & VARIABLES HERE #
#################################

TAPE="/usr/openv/netbackup/bin/lto-fullt.mail"
FULL_TAPES"/usr/openv/netbackup/bin/full_tapes"

#####################
# BEGINNING OF MAIN #
#####################

for i in "${TAPE}"
do
   cat $TAPE |awk '{ print $1 }' | paste -d : -s > full_tapes
done

for j in "${FULL_TAPES}"
do
   /usr/openv/volmgr/bin/vmchange -res -multi_eject -w -verbose -rn 0 -rt TLD -rh bkup2 ml $FULL_TAPES


if [ "j" -eq 0 ] ; then
            echo "$FULL_TAPES Ejected successfully "
        else
             echo "$FULL_TAPES Eject failed"
         fi
       else
            echo "$FULL_TAPES not in library "
     fi
  fi
done

The full_tapes media_id looks like.

L012345
L045583
L012314
L098008
L043243
L076865
L099002
L000883
L032329
L045768
L034567
L012908
L056742
L090723
L000012
L090972
L001221
L001102
L007881
L001229
L000912
L000898

After paste -d : -s

L012345:L045583:L012314:L098008:L043243:L076865:L099002:L000883:L032329:L045768:
L034567:L012908:L056742:L090723:L000012:L090972:L001221:L001102:L007881:L001229:
L000912:L003452:L001222:L000081:L000082:L000181:L000002:L000454:L000456:L000459:
L000239:L000231:L000991:L000993:L000349:L000003:L000023:L000087:L001220:L003344

I'm surprised that code works at present, you've got three end ifs (fi), two elses, but only one if statement. All a bit weird. Is this the full script or just an excerpt?

If you just want to issue some command against each bunch of 15 tapes seperated by : characters, try this:

TAPE="/usr/openv/netbackup/bin/lto-fullt.mail"   # Taken from your script above
tapes=0
for $thistape in `awk '{ print $1 }' < $TAPE`   # Again from your script above
do
  if [ $tapes -eq 0 ]
  then
    tapelist=$thistape
  else
    tapelist="${tapelist}:${thistape}"
  fi
  if [ $tapes -ge 15 ]
  then
    your eject command on $tapelist
    tapes=0
  fi
done

Not tested of course.

i may have forgotten to delete those extra ones in there, but yes this is the full script.

i have not test it out. i've been working on the other part to get the ":" added to my full_tapes file.

i was also going to ask, would using sort or asort work to separate the tapes into groups of 15?

---------- Post updated at 09:37 PM ---------- Previous update was at 09:32 PM ----------

thanks smiling dragon. i'll give that a try.