UNIX Hints & Hacks

ContentsIndex

Chapter 1: Topics in Administration

 

Previous ChapterNext Chapter

Sections in this Chapter:

1.1 Collecting System Information

 

1.7 Swap on-the-Fly

 

1.13 Remove the ---- Dashes ----

1.2 Backup Key Files!

 

1.8 Keep It Up with nohup

 

1.14 echo Does ls

1.3 Execution on the Last Day of a Month

 

1.9 Redirecting Output to Null

 

1.15 Building Large Dummy Files

1.4 Dealing with Unwanted Daemons

 

1.10 Keeping Remote Users Out

 

1.16 Burning-in Disk Drives

1.5 Keep Those Daemons Running

 

1.11 Rewinding Tapes Fast

 

1.17 Bringing a System Down

1.6 fuser Instead of ps

1.12 Generating a Range of Numbers

 

 

1.11 Rewinding Tapes Fast

1.11.1 Description

1.11.1 Description

You are all aware that you can rewind tapes the old-fashioned way with the mt command, but there is a faster way.

Example

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.

Step 2: Rewind the tape.

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.

Reason

This little hack is merely a shortcut to using the magnetic tape rewind command that comes with UNIX.

$ mt -f /dev/rmt/0cbn rewind

Real Word Experience

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

Other Resources

Man pages:

mt

UNIX Hints & Hacks

ContentsIndex

Chapter 1: Topics in Administration

 

Previous ChapterNext Chapter

Sections in this Chapter:

1.1 Collecting System Information

 

1.7 Swap on-the-Fly

 

1.13 Remove the ---- Dashes ----

1.2 Backup Key Files!

 

1.8 Keep It Up with nohup

 

1.14 echo Does ls

1.3 Execution on the Last Day of a Month

 

1.9 Redirecting Output to Null

 

1.15 Building Large Dummy Files

1.4 Dealing with Unwanted Daemons

 

1.10 Keeping Remote Users Out

 

1.16 Burning-in Disk Drives

1.5 Keep Those Daemons Running

 

1.11 Rewinding Tapes Fast

 

1.17 Bringing a System Down

1.6 fuser Instead of ps

1.12 Generating a Range of Numbers

 

 

© Copyright Macmillan USA. All rights reserved.