# Tar

**URL:** <https://community.unix.com/t/tar/141663>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [March 9, 2002, 3:35am UTC](https://community.unix.com/t/tar/141663 "2002-03-09T03:35:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddyvdv](https://community.unix.com/letter_avatar/eddyvdv/32/6_449c533f586939b6e5f246632a46421f.png) [@eddyvdv](https://community.unix.com/u/eddyvdv)\
**Post date:** [March 9, 2002, 3:35am UTC](https://community.unix.com/t/tar/141663/1 "2002-03-09T03:35:22Z")

</div>

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.😕

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [March 9, 2002, 9:35am UTC](https://community.unix.com/t/tar/141663/2 "2002-03-09T09:35:22Z")

</div>

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):

```nohighlight
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'

```

---

<div class="post-metadata">

**Author:** ![eddyvdv](https://community.unix.com/letter_avatar/eddyvdv/32/6_449c533f586939b6e5f246632a46421f.png) [@eddyvdv](https://community.unix.com/u/eddyvdv)\
**Post date:** [March 9, 2002, 1:14pm UTC](https://community.unix.com/t/tar/141663/3 "2002-03-09T13:14:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [March 9, 2002, 1:20pm UTC](https://community.unix.com/t/tar/141663/4 "2002-03-09T13:20:51Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [March 9, 2002, 1:42pm UTC](https://community.unix.com/t/tar/141663/5 "2002-03-09T13:42:46Z")

</div>

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

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

```

or

```nohighlight
#!/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
