Last active
December 13, 2018 17:25
-
-
Save mhglover/5255715 to your computer and use it in GitHub Desktop.
bash script for brute-force loading and unloading tapes from a Quantum Superloader 3 via the HTML management console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wget="/usr/local/bin/wget" | |
username="user" | |
password="pass" | |
IP="10.0.0.1" | |
#this is a file used to stash the origin slot for the tape currently in the tape drive | |
homefile="$SCRIPTDIR/drive-status.txt" | |
SCRIPTDIR=$( cd "$( dirname "$0" )" && pwd ) | |
HOMESLOT=$(<$homefile) | |
DRIVE="17" | |
scripted="1" | |
# Slots 1 - 16 | |
# Drive is 17 | |
# Mailslot (Tape Ejecter) is 18 | |
# Picker is 19 | |
#should be able to: | |
#load from slot to drive autoloader.sh -l 3 | |
#unload from drive to originating slot autoloader.sh -u | |
#move from drive to given slot autoloader.sh -m 7 | |
#force unload to a given slot autoloader.sh -f 2 | |
function movetape { | |
arg1=$1 | |
arg2=$2 | |
arg3=$3 | |
echo "moving from $arg1 to $arg2 (home= $HOMESLOT)" | |
exiter="1" | |
while [ "$exiter" -ne "4" ]; do | |
#a "no data received" page signifies success and gives us exit code 4 | |
#any other page (302, for example) signifies failure, so we should try again | |
$wget -q --http-user=$username --http-password=$password "http://$IP/move.cgi?from=$arg1&to=$arg2" -O /dev/null --max-redirect=0 -t 1 > /dev/null 2>&1 | |
exiter=$? | |
sleep 2 #add a little delay between tries | |
#this should also have a timeout after five tries or so with a failure message | |
done | |
if [ "$arg2" -eq "$DRIVE" ]; then | |
HOMESLOT=$arg1 | |
echo $HOMESLOT > $homefile | |
echo "tape from $HOMESLOT loading in drive" | |
else | |
HOMESLOT="" | |
echo $HOMESLOT > $homefile | |
echo "tape unloading to $arg2, drive now empty" | |
fi | |
#wait a while for the drive to work - two minutes seems about right | |
echo "waiting two minutes" | |
sleep 120 | |
if [ -z $arg3 ]; then | |
#send a growl notification to me | |
ssh 10.0.0.2 "/usr/local/bin/growlnotify '$HOSTNAME alert' -m 'hopefully done moving tapes' -s" | |
echo "done moving" | |
fi | |
} | |
if [ -z $HOMESLOT ]; then | |
echo "drive is empty" | |
else | |
echo "drive is loaded from slot $HOMESLOT" | |
fi | |
while getopts "ul:m:f:s" opt; do | |
case $opt in | |
s) | |
#this variable is boolean backwards - if we're running this from a script, we use the -s switch | |
#and it won't send growl notifications | |
scripted="" | |
;; | |
l) | |
#check to see if homeslot is empty | |
if [ -z $HOMESLOT ]; then | |
#if it's empty, load normally | |
movetape $OPTARG $DRIVE | |
else | |
# if it's not empty, there's a tape in the drive | |
#check to see if homeslot has desired tape number | |
if [ "$HOMESLOT" -eq "$OPTARG" ]; then | |
#if so, echo and do nothing | |
echo "the tape from slot $OPTARG is already in the drive (according to $homefile)" | |
else | |
#if not, unload current tape to home and wait | |
movetape $DRIVE $HOMESLOT | |
#then load desired tape and write to homefile | |
movetape $OPTARG $DRIVE $scripted | |
fi | |
fi | |
;; | |
u) | |
#check to see if homefile is empty | |
if [ -z $HOMESLOT ]; then | |
echo "there is no tape in the drive (according to $homefile)" | |
else | |
movetape $DRIVE $HOMESLOT $scripted | |
fi | |
;; | |
m) | |
#unload tape to specific slot, rather than its homeslot | |
#will be rarely used | |
#check to see if homefile is empty | |
if [ -z $HOMESLOT ]; then | |
#if so, comment | |
echo "there is no tape in the drive (according to $homefile)" | |
else | |
movetape $DRIVE $OPTARG $scripted | |
fi | |
;; | |
f) | |
#force unload to specific slot | |
#used when the homefile is incorrectly empty | |
echo "forcing unload to $OPTARG from drive" | |
movetape $DRIVE $OPTARG $scripted | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" | |
exit 1 | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment