Skip to content

Instantly share code, notes, and snippets.

@adamstadnick
Last active November 21, 2017 16:01
Show Gist options
  • Save adamstadnick/49146b00022e206786777aa061905dbe to your computer and use it in GitHub Desktop.
Save adamstadnick/49146b00022e206786777aa061905dbe to your computer and use it in GitHub Desktop.
Powershell script to automate tape exports on Quantum SuperLoader 3
<#
.SYNOPSIS
Powershell Script to automate tape ejection from Quantum SuperLoader 3, since Quantum is adamant that this is impossible to do.
.DESCRIPTION
The script accepts three arguments - source tape slot, destination tape slot, and a flag to skip notification of job completion.
Operation:
Slots are numbered 1 - 16
Drive is 17, Mailslot is 18 and Picker is 19
Or specify using Drive, MailSlot, and Picker instead of numbers
.EXAMPLE
changer.ps -From 1 -To MailSlot
Moves tape from slot 1 to the Mail Slot.
changer.ps -From 8 -To 5 Silent
Moves tape from slot 8 to slot 5 and does not send a message.
changer.ps -From 4 -To Drive
Moves tape from slot 4 to tape drive.
.NOTES
Original bash script by mhglover at https://gist.github.com/mhglover/5255715
I removed the logic that used the drive as an intermediary destination and tracked where the tapes went as I only needed this to export tapes after job completion
Occasionally the drive returns HTTP 401 but works anyway, the code has logic to handle this. If anyone figures out why and how to fix it please reply and let me know.
.LINK
https://gist.github.com/adamstadnick/49146b00022e206786777aa061905dbe
#>
param([string]$From = $null, [string]$To = $null, [string]$Silent = $null)
$homeslot = $From
$Drive = 17
$Mailslot = 18
$Picker = 19
if ( $To -eq 'MailSlot' ) { $To = $MailSlot }
if ( $To -eq 'Drive' ) { $To = $Drive }
if ( $To -eq 'Picker' ) { $To = $Drive}
if ( $From -eq 'MailSlot' ) { $From = $MailSlot }
if ( $From -eq 'Drive' ) { $From = $Drive }
if ( $From -eq 'Picker' ) { $From = $Drive}
$PC = 'PCNAME' # PC to send message to on successful completion
$msg = 'Done moving tapes.' # Message to send to PC on successful completion
$URI = "http://IP.OF.YOUR.SUPERLOADER/move.cgi?from=$From&to=$To"
$pass = ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force
$user = 'USERNAME'
$cred = New-Object System.Management.Automation.PSCredential($user,$pass)
$userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT; Windows NT 6.1; en-US)" #This caused some problems when I removed it, not sure why it's needed
function movetape () {
$counter = 0
$exiter = 0
Write-Host "Attempting move from $From to $To"
if ( $counter -gt 5 ) {
send-mailmessage -to "Your Name <you@yourcompany.com>" -from "SERVICE NAME <serviceemail@yourcompany.com>" -subject "Tape Script Failure" -body "The tape moving script reports it has failed after 5 attempts."
exit
}
else {
if ($counter -le 5 -and $counter -ne 0)
{
write-host "Retrying, attempt number $counter."
}
while( "$exiter" -lt "1" ) {
try {
$exiter = ( Invoke-WebRequest -URI $URI -Credential $cred -UserAgent $userAgent )
}
catch {
$exiter = $_.Exception.Response.StatusCode.Value__
}
if( $exiter -eq 401 -and $counter -eq 0){
Write-Host "Command most likely worked (returned 401, first attempt - this happens sometimes), continuing."
$counter++
}
elseif( $exiter -eq 401 -and $counter -ne 0 -and $counter -le 5){
Write-Host "Bad command, drive busy or login problem. Please check the drive and verify mail slot is clear."
$counter++
}
elseif( $exiter -eq 504){
Write-Host "Command sent successfully (returned 504), continuing."
$exiter = 1
}
elseif( $exiter -eq 401 -and $counter -ge 5){
Write-Host "Multiple errors. Exiting."
exit
}
else {
Write-Host "Command appears to have worked, continuing."
}
sleep 2 #Add a short delay between tries
}
}
# Logic to handle a few edge cases
if ( $HOMESLOT -eq $null ) {
Write-Host "No source slot specified."
}
else{
Write-Host "Tape retrieved from slot $HOMESLOT."
}
if ( "$To" -eq "$DRIVE" ) {
$HOMESLOT = $From
Write-Host "Tape from $HOMESLOT loading in drive."
}
elseif ( "$To" -eq "$Mailslot") {
$Homeslot = $From
Write-Host "Tape from $Homeslot preparing for ejection."}
else {
$HOMESLOT = $null
Write-Host "Tape is moving to slot $To."
}
#Wait a while for the drive to work - two minutes works and gives a nice buffer
Write-Host "Waiting for command to complete (two minutes)."
sleep 120
#Check if silent flag is set, (any value sent as third argument to script) and cancel message sending if so
if ( $Silent )
{write-host silent flag set, no message
}
else {
#Remind me to pick up the tape :)
msg * /server:$PC $msg
}
}
movetape
@adamstadnick
Copy link
Author

Still debugging, but close to 100% working now.

@npetrakis51
Copy link

GREAT WORK!!!!
Would the numbers for a 8 slot be 1-8 for open slots then 9 for drive, 10 for mail, and 11 for picker???

@npetrakis51
Copy link

bitmoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment