LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-25-2016, 03:38 PM   #1
4evernoob
LQ Newbie
 
Registered: May 2004
Posts: 8

Rep: Reputation: 0
Bash script questions for tape drive control mt and mtx


Trying to monitor the status of a tape drive with mt and mtx and I'm looking for a way to parse the output and resolve to an answer to "the question".
First question, "is the tape drive busy"? mt will return:

[root@c7 ~]# mt -f /dev/nst0 status
/dev/nst0: Device or resource busy

I tried to capture that in a variable:
[root@c7 ~]# TapeTest=$(mt -f /dev/nst0 status)
/dev/nst0: Device or resource busy
[root@c7 ~]# echo $TapeTest
[root@c7 ~]#
The output inexplicably refuses to be captured here. I figured there are some folks here that could make easy work of this problem. I have most of the script written for what I'm doing but have run into a need to check some of this for control.

Test for tape drive status. Possible outputs for mt -f /dev/nst0 status is:
/dev/nst0: Device or resource busy
or
SCSI 2 tape drive:
File number=-1, block number=-1, partition=0.
Tape block size 0 bytes. Density code 0x0 (default).
Soft error count since last status=0
General status bits on (10000):
IM_REP_EN

I'm thinking key word busy should get this so I need a go no go test for it.

Next item is checking to see which tape is loaded in tape drive.
mtx -f /dev/sg13 status
Storage Changer /dev/sg13:1 Drives, 17 Slots ( 0 Import/Export )
Data Transfer Element 0:Full (Storage Element 1 Loaded):VolumeTag = 000115S
Storage Element 1:Empty
Storage Element 2:Full :VolumeTag=000118S
Storage Element 3:Full :VolumeTag=000119S
Storage Element 4:Full :VolumeTag=000120S
Storage Element 5:Full :VolumeTag=000121S
Storage Element 6:Full :VolumeTag=000122S
Storage Element 7:Full :VolumeTag=000123S
Storage Element 8:Full :VolumeTag=000124S
Storage Element 9:Full :VolumeTag=000125S
Storage Element 10:Full :VolumeTag=000126S
Storage Element 11:Full :VolumeTag=000127S
Storage Element 12:Full :VolumeTag=000128S
Storage Element 13:Full :VolumeTag=000129S
Storage Element 14:Full :VolumeTag=000130S
Storage Element 15:Full :VolumeTag=000131S
Storage Element 16:Full :VolumeTag=000132S
Storage Element 17:Full

Need to resolve out to variables which storage element is empty and if none of them are then there must not be a tape in the drive and storage element 1 loaded with what volumeTag.

Show me your ninja.
Thanks in advance.
 
Old 08-25-2016, 06:59 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,704

Rep: Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897
In the case of the drive being busy mt writes to stderr and not stdout which is why echo $TapeTest does not output anything. Its been awhile and I do not have a tape drive connected to a running system at the moment so I can not confirm that the normal status writes to stdout. So here is part I

You can capture stdout and stderr via the command
Code:
TapeTest=$( mt -f /dev/st0 2>&1 )
Code:
And you should be able check via regex
if [[ $tapetest =~ [busy]$ ]]; then

fi
 
Old 08-25-2016, 08:00 PM   #3
4evernoob
LQ Newbie
 
Registered: May 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Cool thanks!
This is what I have so far. At least I think so. Tape drive busy backing up so I can't test this yet against a non busy tape drive. Confidence is high though.

while true; do
TapeTest=$(mt -f /dev/nst0 status 2>&1)
if [[ $TapeTest =~ [busy]$ ]]; then
echo sleeping 10sec
sleep 10
else
break
fi
done

Ok now to tackle what tape is loaded and from what slot.

???
 
Old 08-25-2016, 11:07 PM   #4
4evernoob
LQ Newbie
 
Registered: May 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Ok so I have the slot figured out however I could use some help cutting this down to just the number.

[root@c7 backup]# ChangerTest=$( mtx -f /dev/sg13 status |egrep -v -w 'Full|Drives' )
[root@c7 backup]# echo $ChangerTest
Storage Element 5:Empty
[root@c7 backup]#


Still need to get that VolumeTag. Anyone?
 
Old 08-26-2016, 01:15 PM   #5
4evernoob
LQ Newbie
 
Registered: May 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Golden!

[root@c7 scripts]# VOLTAG=$( mtx -f /dev/sg13 status |grep Loaded.*VolumeTag |awk '{ print $10 }' )
[root@c7 scripts]# GNGRSLOT=$( mtx -f /dev/sg13 status |grep Loaded.*VolumeTag |awk '{ print $7 }' )
[root@c7 scripts]# echo "Changer slot = $GNGRSLOT"
Changer slot = 7
[root@c7 scripts]# echo "VolumeTag = $VOLTAG"
VolumeTag = 000123S

For the next guy.
I'm out.

Last edited by 4evernoob; 08-26-2016 at 01:16 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] HP DEC TZ88N-TA Tape Drive Maintenance 2*Questions hdp160 Linux - Hardware 7 08-21-2012 01:37 PM
[SOLVED] Script to Detect whether tape exist in tape drive or not dctw Linux - General 3 12-17-2010 03:04 AM
Simple tape drive questions helpmhost Linux - Hardware 2 12-29-2006 12:54 AM
need script to query tape drive Finlay Linux - Software 14 07-22-2004 07:43 PM
2 questions(Re: backup to scsi tape drive) ascii2k Linux - General 5 07-16-2001 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration