Need help updating my AIX shell script that uses IBM tape tool.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help updating my AIX shell script that uses IBM tape tool.
# 1  
Old 12-09-2015
Error Need help updating my AIX shell script that uses IBM tape tool.

I have a shell script that interfaces with our tape library using IBM's Tape Diagnostic tool called "itdt".

The script does some basic stuff, it queries the tape library, loads tape to/from drive; it knows which inventory slot to pick the tape from based on SLOT=$(($BASESLOT + $TODAY)).

The problem is, this only ever interacts with the first 7 tapes in a 24 tape library because TODAY=`date +%w` is going to return values from 1-7 depending on the day of the week the script runs.

Using $TODAY is not ideal because it only ever loads/unloads the first 7 tapes in a 23 tape library.

Anyone able to give some pointers as to how I would update this script so that it fully utilizes all 23 tape slots. What other method could I use instead of..

Code:
TODAY=`date +%w`
BASESLOT=4096
SLOT=$(($BASESLOT + $TODAY))

to make use of all 23 slots.. below is full script..

Code:
inventory()
{
  echo "Tape Inventory"
  echo " "

  query_inventory
  query_drive

  echo "Slot  - Tape"
  i=0
  while [ $i -lt $MAXSLOTS ]
  do
    echo "$(($BASESLOT + $i))  - ${SLOTS[$i]}"
    ((i=$i+1))
  done

  echo " "
  echo "Drive - $TAPEINDRIVE"
  echo " "
}

load()
{
  query_inventory
  query_drive

  TAPEINSLOT=${SLOTS[$TODAY]}

  if [[ $TAPEINSLOT = " " ]]; then
    echo "Unable to load tape - today's slot is empty"
    exit
  fi

  if [[ $TAPEINDRIVE != "None" ]]; then
    echo "Unable to load tape - tape $TAPEINDRIVE is already in the drive"
    exit
  fi

  echo "Moving tape $TAPEINSLOT from slot $SLOT to drive"

  RETURN=`$ITDT -f $DEVICE move $SLOT $DRIVE`
  
}

query_drive()
{
  TAPEINDRIVE=`$ITDT -f $DEVICE inventory | \
    grep -p "Drive Address" | grep 'Volume Tag' | cut -c 34-42`

  [[ $TAPEINDRIVE = " " ]] && TAPEINDRIVE="None"
}

query_inventory()
{
  INVENTORY=$($ITDT -f $DEVICE inventory)

  i=0
  while [ $i -lt $MAXSLOTS ]
  do
    TMPSLOT=$(($BASESLOT+$i))
    SLOTS[$i]=`echo "$INVENTORY" | \
      grep -p "Slot Address ................... $TMPSLOT" | \
      grep 'Volume Tag' | cut -c 34-42`
    ((i=$i+1))
  done
}

unload()
{
  query_inventory
  query_drive

  if [[ $TAPEINDRIVE = "None" ]]; then
    echo "Drive is empty. There is nothing to unload!"
    exit
  fi

  if [[ ${SLOTS[$TODAY]} != " " ]]; then
    echo "Todays slot is occupied. Looking for available slot"
    SLOT="Occupied"
    i=0
    while [ $i -lt $MAXSLOTS ]
    do
      if [[ ${SLOTS[$i]} = " " ]]; then
        SLOT=$(($BASESLOT + $i))
        echo "Found available slot $SLOT"
        break
      fi
      ((i=$i+1))
    done
    if [[ $SLOT = "Occupied" ]]; then
      echo "Unable to find a free slot. Unable to unload tape"
      exit
    fi
  fi

  echo "Moving tape $TAPEINDRIVE from drive to slot $SLOT"

  RETURN=`$ITDT -f $DEVICE move $DRIVE $SLOT`


}

usage()
{
  echo "   usage: tapes load"
  echo "          tapes unload"
  echo "          tapes inventory"
  echo " "
}

if [ $# != 1 ]; then
  usage
  exit
fi

DEVICE=/dev/rmt0
ITDT=/usr/local/bin/itdt
DRIVE=256
TODAY=`date +%w`
BASESLOT=4096
SLOT=$(($BASESLOT + $TODAY))
MAXSLOTS=23
TAPEINDRIVE="None"

case "$1" in
  load) load; exit;;
  unload) unload; exit;;
  inventory) inventory; exit;;
  *) usage; exit;;
esac


Last edited by Don Cragun; 12-09-2015 at 06:26 PM.. Reason: Add more CODE and ICODE tags.
# 2  
Old 12-10-2015
If you're trying to use slots 4097 through 4119 approximately the same number of times in a round robin order based on the date (as opposed to keeping track of what had been used the last time your script was called), you could try something like:
Code:
DATE=$(date '+%j')	# Get Julian day of year.
DATE=${DATE#0}		# Strip leading zeros to guarantee decimal (rather
DATE=${DATE#0}		# than octal) evaluation of DATE when computing SLOT.
BASESLOT=4096
SLOT=$((BASESLOT + 1 + ((DATE - 1) % 23)))


Last edited by Don Cragun; 12-10-2015 at 11:44 AM.. Reason: Fix typos: s/{date/{DATE/g
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 12-10-2015
Should BASESLOT be included in the selection of slots, i.e. does 4096 address a correct tape? Then the + 1 needs to be omitted.
And, I guess DATE=${date#0} should read DATE=${DATE#0}
This User Gave Thanks to RudiC For This Post:
# 4  
Old 12-10-2015
Quote:
Originally Posted by RudiC
Should BASESLOT be included in the selection of slots, i.e. does 4096 address a correct tape? Then the + 1 needs to be omitted.
And, I guess DATE=${date#0} should read DATE=${DATE#0}
Thanks for catching the date vs. DATE issue; that has now been fixed in my earlier post.

I don't think 4096 was intended to be included based on using date +%u (which returns 1-7; not 0-6) in the existing code. But, the original post also mentioned 23 a few times, but 24 once; and, it never mentioned the desired range of slot numbers to be assigned.
# 5  
Old 12-10-2015
Thanks for the quick responses Smilie

The tape library has 24 slots, the way they are counted is 23 slots + 1 tape head/drive slot.

The address of the first tape slot is 4096 and the address of the last (slot 23) is 4118; i'd like all of them to be used in a round robin kind of method. The idea is, this script gets called nightly to "change tapes" before the backup to tape happens. So every night it should be using a different tape (+1) until it reaches the 23rd tape (address 4118) then goes back to 1 (address 4096).

Sorry for the lack of information, I hope this is more complete now.

With the above changes you suggested, will it support this? When I made the above changes and ran the script, it loaded the tape from slot 4118... i'll try again tomorrow to see if it loads from 4096.

Last edited by c3rb3rus; 12-10-2015 at 07:05 PM.. Reason: add more details
# 6  
Old 12-10-2015
Quote:
Originally Posted by c3rb3rus
Thanks for the quick responses Smilie

The tape library has 24 slots, the way they are counted is 23 slots + 1 tape head/drive slot.

The address of the first tape slot is 4096 and the address of the last (slot 23) is 4118; i'd like all of them to be used in a round robin kind of method. The idea is, this script gets called nightly to "change tapes" before the backup to tape happens. So every night it should be using a different tape (+1) until it reaches the 23rd tape (address 4118) then goes back to 1 (address 4096).

Sorry for the lack of information, I hope this is more complete now.

With the above changes you suggested, will it support this?
As I originally stated in post #2 in this thread:
Quote:
If you're trying to use slots 4097 through 4119 approximately the same number of times in a round robin order based on the date (as opposed to keeping track of what had been used the last time your script was called)...
so if you want to use slots 4096 through 4118, you should change:
Code:
SLOT=$((BASESLOT + 1 + ((DATE - 1) % 23)))

in that script to:
Code:
SLOT=$((BASESLOT + ((DATE - 1) % 23)))

Note that it will reset to SLOT 4096 on January 1st every year leaving a few tapes unused in the last rotation of the year.
# 7  
Old 02-09-2016
I finally got around trying this, I was thinking it may be best we track this in a file instead of using something like DATE. The file could be incremented from 1 - 23 to determine $SLOT, then reset to 1 once it reaches 23 (would be easier to troubleshoot as well).

Any chance you could provide an example of doing this the alternate method you suggested (keeping track of it)?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help updating my AIX shell script that uses IBM tape tool.

I have a shell script that interfaces with our tape library using IBM's Tape Diagnostic tool called "itdt". The script does some basic stuff, it queries the tape library, loads tape to/from drive; it knows which inventory slot to pick the tape from based on SLOT=$(($BASESLOT + $TODAY)). The... (1 Reply)
Discussion started by: tmonk1
1 Replies

2. AIX

IBM Virtual Machine OS on intel x86 and x64? IBM AIX OS on IBM Virtual Machine?

Hi There, I have zero information and zero knowledge for IBM virtual machine except Amazon cloud and VMware ESXi (Only Linux OS available). Anyone could provide me the following answer - Can IBM VM been deploy on X86 and X64 (Intel Chip)? If answer is yes any chance to deploy AIX OS... (13 Replies)
Discussion started by: chenyung
13 Replies

3. Shell Programming and Scripting

Shell script executed from Informatica ETL tool is spawning 2 processes for one script

Hi, I am having a shell script which has a while loop as shown below. while do sleep 60 done I am executing this script from Informatica ETL tool command task from where we can execute UNIX commands/scripts. When i do that, i am seeing 2 processes getting started for one script... (2 Replies)
Discussion started by: chekusi
2 Replies

4. Shell Programming and Scripting

I want a script to view the complete log information of data stage job from UNIX IBM AIX.

Hi, I am working on data stage 8.7 version and I want a script a to view the all log information of the data stage job from UNIX environment. Can you please help me out by give the script. Thanks in advance... (7 Replies)
Discussion started by: victory
7 Replies

5. AIX

Ejecting tape on AIX & Some Tape commands

I am trying to use this command to eject the tape mt -f /dev/rmt/0 unload but it gives me error mt -f /dev/rmt/0 unload mt: 0511-575 unload is not a recognized subcommand. Usage: mt Subcommand Valid subcommands are: weof eof fsf bsf ... (5 Replies)
Discussion started by: filosophizer
5 Replies

6. Shell Programming and Scripting

Need help in updating the tables inside shell script

I have an input file with contents like : 1LMXTJJD0W28TX2 1LS1XJGDEVWAC5T 1LK81JVDE2HRNDG 1LMXTJJD0W28TX2 1LS1XJGDEVWAC5T 1LK81JVDE2HRNDG 1LMXTJJD0W28TX2 I need to read each field from the file pass it to a query: select count(*) from usage_error where usage_id='$field... (17 Replies)
Discussion started by: Rajesh Putnala
17 Replies

7. AIX

IBM AIX on IBM Eseries & x series server

Hi, I want to know whether IBM AIX can be installed on the IBM e series and x series server hardware? Thanks & Regards Arun (2 Replies)
Discussion started by: Arun.Kakarla
2 Replies

8. AIX

Backup script for Aix without tape mount

Hi, My situation is to write a backup script for AIX server which doesnt have a tape mounted. They have created a folder on windows so that all AIX backup files can be moved to that windows folder where they will put these AIX backup files on a tape. Appreciate help. Regards dsrules. (7 Replies)
Discussion started by: dsrules
7 Replies

9. Shell Programming and Scripting

updating a column in oracle table using shell script

Hi friends, i am having a variable declared in .profile.i am changing its value in a shell script and then i am connecting to oracle and then from there i am calling a .sql called update.sql STATUS is the variable declared in the .profile =============================== if sqlplus <<END... (3 Replies)
Discussion started by: sveera
3 Replies
Login or Register to Ask a Question