The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script Assistance jaysunn Shell Programming and Scripting 2 05-08-2009 05:36 PM
shell script assistance please xinoo Shell Programming and Scripting 5 08-05-2008 12:18 PM
need assistance ----SH schell script shahidbakshi Shell Programming and Scripting 2 02-22-2008 06:28 AM
Need a little assistance with a shell script rickou812 Shell Programming and Scripting 3 02-04-2008 04:18 AM
KSH Script Assistance Brusimm Shell Programming and Scripting 3 05-10-2007 09:15 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-19-2009
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
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.


Code:
#!/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.

Code:
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

Code:
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

  #2 (permalink)  
Old 08-19-2009
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
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:

Code:
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.
  #3 (permalink)  
Old 08-19-2009
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
Quote:
Originally Posted by Smiling Dragon View Post
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:

Code:
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.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0