severity 297527 wishlist
thanks

Jules Alberts <[EMAIL PROTECTED]> writes:

> `mt-st status` returns text like this:
> 
> ---snippet----------------------------------------
> SCSI 2 tape drive:
> File number=0, block number=0, partition=0.
> Tape block size 0 bytes. Density code 0x47 (TR-5).
> Soft error count since last status=0
> General status bits on (41010000):
>  BOT ONLINE IM_REP_EN
> ---end snippet------------------------------------
> 
> and the errorlevel is 0 regardless of the actual tape drive status. 

I assume you mean "exit status".

> If you want a shell script to check the status of the tape, it has
> do do a grep on the output, which is errorprone, especially if the
> author of mt-st would change the returned text in a future
> version. The use of an errorlevel (e.g. 0 if tape is online, 1 if
> offline etc.) would solve this.

man mt-st says:

       mt  exits with a status of 0 if the operation succeeded, 1
       if the operation or device name given was invalid, or 2 if
       the operation failed.

'mt-st status' performs according to the documentation: it exits with
an exit status of 0 because it successfully retrieved the tape drive
status information.  Therefore it's not an important bug, and I've
downgraded your bug's severity to 'wishlist'.

I do not think that returning a special exit status for the absence of
the ONLINE flag is a good idea.  Tape drives some in different makes
and they do not all report "tape inserted" as "ONLINE" and "tape
ejected" as "! ONLINE".  My Sony DDS drive reports ejected as 
"! ONLINE && DR_OPEN" and inserted as "ONLINE && ! DR_OPEN".  I have
seen some other drives not reporting DR_OPEN.  So it's not clear cut
how inserted is defined.  The current behavior is at least consistent.

As for your application of detecting an open tape drive I'd suggest
sed'ing and grep'ing like this:

   LC_ALL=C mt stat 2> /dev/null \
   | sed -e '1,/^General status bits/d' \
         -e '/^[^[:space:]]/,$d' \
   | grep -q '[[:space:]]ONLINE\([[:space:]]\|$\)'
   if [ $? -eq 0 ]
   then
     echo "Tape inserted"
   fi

(tested to work against mt-st and mt-gnu, BTW)

That should isolate you as much as possible from change in the mt-st
output format. 

Alternately, just open the tape for reading.  It will fail unless a
tape is inserted:

   (true < $TAPE ) >& /dev/null && echo "Tape inserted"

Hope this helps,
Phil.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to