O'Reilly logo

Time Management for System Administrators by Thomas A. Limoncelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hard Things Done Once

When we find ourselves doing something very difficult, automating the task records what we've done. When we do it in the future, it will be easier. This is how we build up our little bag of tricks.

Encapsulating a Difficult Command

Sometimes it takes hours to work out exactly the right command required to do something. For example, there is a program that creates ISO images, the kind you burn onto CD-ROMs. Its manual page describes hundreds of options, but to make an image readable by Windows, Unix, and Mac systems, the command is simply:

    $ mkisofs -D -l -J -r -L -f -P "
               
                  Author Name
               
               " -V "
               
                  disk label
               
               " -copyright
      copyright.txt -o
               
                  disk.iso /directory/of/files
               

Sure, you can do it from a GUI, but where's the fun (or ability to script) in that?

This command also lets you do things not found in most GUIs, such as the ability to specify a copyright note, author name, and so on.

This is a good example of something to work into a .BAT file (DOS) or a Unix/Linux shell script.

Here's a shell script called makeimage1 that uses this:

    #!/bin/bash

    mkisofs -D -l -J -r -L -f -P "Limoncelli" -V 'date -u +%m%d' $*

The 'date -u +%m%d' sets the volume name to the current date.

One of the things that held me back from writing good scripts was that I didn't know how to process command-line parameters. Here are instructions for copying all the command-line arguments into a script.

The $* in the makeimage1 script means "any items on the command line." So, if you typed:

    $ makeimage1 cdrom/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required