Chapter 5: System Administration: Managing Users


Overview

No sophisticated operating system can run itself without some human intervention, whether it's Windows, Mac OS, or Unix. If you use a multiuser Unix system, someone no doubt is performing the necessary system administration tasks . You might be able to ignore the proverbial "man behind the curtain" who is managing and maintaining everything, or you might well be the All Powerful Oz yourself, the person who pulls the levers and pushes the buttons to keep the system running. Even if you have a single- user system, like a Linux or Mac OS X system, there are system administration tasks that you should be performing, whether you realize it or not.

Fortunately, streamlining life for Unix system administrators is one of the most common uses of shell scripting, and as a result there are quite a few different shell scripts that sysadmins use, from the simple to the complex. In fact, there are usually quite a few commands in Unix that are actually shell scripts, and many of the most basic tasks, like adding users, analyzing disk usage, and managing the filespace of the guest account, can easily be done in relatively short scripts.

What's surprising is that many system administration scripts are no more than 20 to 30 lines long, total. This can be easily calculated on the command line for a given directory:

 $  wc -l $(file /usr/bin/*  grep "script"  grep -v perl  cut -d: -f1)  \   sort -n  head -15  3 /usr/bin/bdftops       3 /usr/bin/font2c       3 /usr/bin/gsbj       3 /usr/bin/gsdj       3 /usr/bin/gsdj500       3 /usr/bin/gslj       3 /usr/bin/gslp       3 /usr/bin/gsnd       4 /usr/bin/4odb       4 /usr/bin/4xslt       4 /usr/bin/krdb       5 /usr/bin/4rdf       5 /usr/bin/4xupdate       6 /usr/bin/checkXML       6 /usr/bin/kdb2html 

None of the shortest 15 scripts in the /usr/bin/ directory are longer than 6 lines. And at 14 lines, the Red Hat Linux 9.0 script /usr/bin/mute is a fine example of how a little shell script can really improve the user experience:

 #! /bin/sh # $Aumix: aumix/src/mute,v 1.1 2002/03/19 01:09:18 trevor Exp $ # Copyright (c) 2001, Ben Ford and Trevor Johnson # # Run this script to mute, then again to un-mute. # Note: it will clobber your saved settings. # volumes=$(aumix -vq tr -d ,) if [ $(echo $volumes  awk '{print }') -ne 0 -o \         $(echo $volumes  awk '{print }') -ne 0 ]; then         aumix -S -v 0 else         aumix -L > /dev/null fi 

Like the mute script, the scripts presented in this chapter are short and useful, offering a range of administrative capabilities, including easy system backups , showing what system services are enabled through both inetd and xinetd , an easy front end to the date command for changing the current date and time, and a helpful tool to validate crontab files.




Wicked Cool Shell Scripts. 101 Scripts for Linux, Mac OS X, and Unix Systems
Wicked Cool Shell Scripts
ISBN: 1593270127
EAN: 2147483647
Year: 2004
Pages: 150
Authors: Dave Taylor

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net