Tar

I want to write a script for taking a backup on a tape device.
How can i check if the device is ready before taking this backup.:confused:

On my HP-UX 11.00, I can do:
mt -t /dev/rmt/0m status

With a tape mounted, I get:

Drive: HP C1537A
Format: DDS-3 format
Status: [41112500] BOT online compression immediate-report-mode
File: 0
Block: 0

With no tape, the Status line is:
Status: [0]

In both cases, $? is zero so I grep the Status line (and that is a tab after the colon, not a space):

mt -t /dev/rmt/0m status |
  grep '^Status:        \[0\]' > /dev/null ||
  echo 'tape mounted'

mt -t /dev/rmt/0m status |
  grep '^Status:        \[0\]' > /dev/null &&
  echo 'no tape mounted'

thanks for the tip but i wanted to use de $?=1 to give me a message. Is there a possibility to do this?

Following command will give you status code of zero when tape is mounted and status code of 1 if not:

mt -t /dev/rmt/0m status |
  if grep '^Status:        \[0\]' > /dev/null ; then
     exit 1
  else
     exit 0
  fi

If you want use the "$?" or "$status", you can do this :

#!/bin/ksh
mt -t /dev/rmt/0m rewind
if [ $? -ne 0 ]; then
   echo "Backup error"
   exit 1
fi

or

#!/bin/csh
mt -t /dev/rmt/0m rewind
if ( $status != 0 ) then
   echo "Backup error"
   exit 1
endif

In this case, you don�t need that your tape is on the driver.

I hope help you !

Witt

added code tags for readability --oombera