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.