UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 1: Topics in Administration |
|
||||||||||||||||||||||||||||||||||||
|
You are all aware that you can rewind tapes the old-fashioned way with the mt command, but there is a faster way.
Flavors: AT&T and BSD
Shells: bsh, bash, ksh
Syntax:
< device
All it takes to force the system to rewind the tape is to redirect the tape device to absolutely nothing.
$ < /dev/rmt/0cbn
Of course, your device name might differ from that in the example.
If you have multiple tape drives attached to a system or you want to save time spent typing the command, you could first set the name of the tape device in your environment variables. Then the command could be even shorter:
$ DAT=/dev/rmt/2n $ DLT=/dev/rmt/0cbn
Step 1: Set the environment variable in the shell for the tape devices.
A practical use for this command is to create a simple script to tar off data to tape, making sure that the tape is rewound in the beginning and in the end.
#! /bin/sh DLT="/dev/rmt/0cbn" < $DLT tar -cvf $DLT /usr/spool/mail < $DLT
Line 1: Define the shell to be used.
Line 3: Set the variable DLT to be the tape device.
Line 4: Rewind the tape device so you are at the beginning.
Line 5: Tar off the files to the tape device.
Line 6: Rewind the device again to the beginning.
This little hack is merely a shortcut to using the magnetic tape rewind command that comes with UNIX.
$ mt -f /dev/rmt/0cbn rewind
Many times you are asked to write data off to tape for users. You can simplify the previous sample script into a one-liner at a shell prompt with
$ < $DLT; tar -cvf $DLT /usr/spool/mail; < $DLT
Man pages:
mt
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 1: Topics in Administration |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.