1851583 Members
3883 Online
104061 Solutions
New Discussion

Re: Tape error messages

 
Merit Europe
Occasional Contributor

Tape error messages

Hi,

Let me try another question, the last one worked out well!

Before we run our backup, we check for the presence of a tape in the drive using the following command:
mt -t $DLT_TAPE rew

Now there are a couple of possible scenarios for the error output, does anyone have a script that catches these error messages ($?), and connects this to a human readable error message?

Thanks in advance,

Robert
4 REPLIES 4
Sridhar Bhaskarla
Honored Contributor

Re: Tape error messages

I would do

mt -t $DLT_TAPE rew 2>/tmp/errlog

if [ `wc -l` -ne 0 ]
then
#Here you can check for various errors and echo
#human readable. Else if you just want to
#print the error
cat /tmp/errlog
rm /tmp/errlog
fi

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Merit Europe
Occasional Contributor

Re: Tape error messages

This is what i do at the moment. I was hoping someone had gathered these error messages for me, as they seem to be undocumented.

Can anyone give some more assistance?
Stefan Farrelly
Honored Contributor

Re: Tape error messages


The only error codes you can really get from using the mt command are 0 (success) or 1 (failure).

So;

mt -t /dev/rmt/0m rew
if [ $? -ne 0 ]
then
echo Either no tape in the drive or tape in use.
fi

The only question is how to test the tape in the drive is writeable ? Doing a rewind will not detect a non-writeable tape. Perhaps you would want to do a write test to the tape also to check its writeable ? (use something like echo > /dev/rmt/0m )
Im from Palmerston North, New Zealand, but somehow ended up in London...
Robin Wakefield
Honored Contributor

Re: Tape error messages

Robert,

Try compiling the following. Basically the "mt_gstat" field is defined in /usr/include/sys/mtio.h and defines the state (including write protect status) of the tape/drive. You'll probably want to play with this to get what you want, but it's a start:

Rgds, Robin

======================================
#include
#include
#include
#include
#include
#include

int main(int argc,char *argv[])
{
/* int argc;
char *argv[]; */
struct mtget mtget;
struct mtop mtop;
char *dev="/dev/rmt/3hcn";
int fd;
if (argc > 2)
{
fprintf(stderr, "Usage: %s \n", argv[0]);
exit(1);
}
if (argc == 2)
dev=argv[1];
/* open the device */
if ((fd=open(dev,O_RDWR))<0)
{
/* printf("\nfd ERROR = %d\n",errno); */
perror("open failed");
exit(errno);
}

if ((ioctl(fd,MTIOCGET,&mtget))<0)
{
perror("ioctl(MTIOCGET) failed");
exit(errno);
}
printf("\nmt_gstat = %x\n",mtget.mt_gstat);
/* else
{
printf("\nmt_gstat = %x\n",mtget.mt_gstat);
if (GMT_BOT(mtget.mt_gstat))
printf("BOT\n");
else if (GMT_EOT(mtget.mt_gstat))
printf("EOT\n");
} */
exit(0) ;
}
==========================================