Cover V05, I08
Article
Listing 1
Listing 2

aug96.tar


Questions and Answers

Bjorn Satdeva

In the June column, there was a question about how to compute yesterday's date in a shell script. I answered that I did not know of a good way and recommended switching to Perl, if at all practical. I think that one answer generated more responses than any other comments and suggestions I have made in this column over the years. Most people pointed out that the date command from the GNU sh-utils is capable of doing this by just providing the appropriate arguments, such as:

% date
Sun Jun 2 14:28:27 EDT 1996

% date _date yesterday
Sat Jun 1 14:28:32 EDT 1996

Besides the suggestion to use the GNU sh-util date command, I received two other suggestions I would like to share, the first one because of its ingenuity and simplicity. Tom Henderson wrote:

Regarding the question about getting the previous day's date in a shell: I picked up a tip for running a script on the last day of the month by "changing" the time zone for a command run via cron. The command makes the date report as the first of the month 24 hours early.

0 6 28-31 * * [ `TZ=PST-16PDT date +\%d` -eq 1 ] && echo "Last day of Month"

The user could do the same, in reverse, to get the date 24 hours earlier by setting TZ with an "hour adjustment" going in the opposite direction. Doing:

TZ=PST+32PDT date

would display the date for the previous day.

Note: Henderson modified the +8 time adjustment by 24 hours because he's in the Pacific Standard Time Zone. Adjust as appropriate for the zone you're in.

I like Henderson's solution for its simplicity. Unfortunately, it does not work across all platforms. On my workstation, it only works within plus or minus a 24-hour period. The TZ=PST+32PDT date gives me current day and time GMT, so be a bit careful with this one.

The second suggestion, includes a complete set of Bourne shell functions that allow some manipulations of date and time from the shell. Judging from the large number of responses, dealing with date and time in a shell script is something many system administrators have been struggling with. Bill Gray wrote:

In June's column, you had a question about producing yesterday's date in the Bourne shell. I believe you are right; there is no easy way, but the following will do it with difficulty (the functions are written for transparency, not efficiency or compactness). They have been tested, but not very extensively because the project they were written for was recoded in Perl(!). Perl's better, but perhaps the person who sent in the query is far along with sh scripts, or doesn't Perl.

The full Bourne functions are shown in Listing 1. To use these functions, do this from a Bourne shell:

$ . yesterday.sh
$ today
$ echo Today: $Ydd $Ymm $Yyy
Today: 02 06 96
$ echo Yesterday: "$Ydd $Ymm $Yyy"
Yesterday: 01 06 96

Thanks to everybody who sent me email about this.

Before I get to this month's questions, here's a small note on something completely different. For those of you interested in standards, I understand from the IEEE that the POSIX Software Administration document is now in the hands of the printers, with an official publication date of June 14, 1996.

The tool of the month is arpwatch. On many sites, system administrators can have problems with systems that appear out of nowhere, for example when a user plugs a new PC into the network. This may happen without any notification to the system administrator, and the user may even choose an address that has been allocated for something else, making havoc out of the network. Arpwatch keeps track of Ethernet/IP address pairs and reports changes, such as a new host appearing on the network, via email. When somebody adds a new host, root will get email with the following content:

To: root
Subject: new station (baldr.sysadmin.com)

hostname: baldr.sysadmin.com
ip address: 10.1.5.101
ethernet address: 0:a0:24:33:27:ff
ethernet vendor: <unknown>
timestamp: Sunday, June 16, 1996 20:43:43 +0100 (PDT)

And when that dreaded thing happens, and somebody configures a machine to use an address that has already been allocated elsewhere, the following email will be sent:

To: root
Subject: changed ethernet address (baldr.sysadmin.com)

hostname: baldr.sysadmin.com
ip address: 10.1.5.101
ethernet address: 0:20:af:8d:a5:28
ethernet vendor: <unknown>
old ethernet address: 0:0:0:33:27:ff
old ethernet vendor: <unknown>
timestamp: Sunday, June 16, 1996 21:25:36 +0100 (PDT)
previous timestamp: Sunday, June 16, 1996 21:25:34 +0100 (PDT)
delta: 2 seconds

Of course, then you have to find the guilty party, which in itself can be a nontrivial undertaking, but at least you will know what has happened.

 Q I now work as a VMS analyst but hope to be a UNIX/NT systems administrator very soon. I have a good working knowledge of UNIX, but there is still a lot I need to learn. Do you have any suggestions as to books, software tools to master, etc?

Thank you for your time and insightful articles in Sys Admin.

 A The number of UNIX system administration books seems to increase every month. However, the number of really good ones is still limited. The ones I really like and think would be useful for you are, first of all, Evi Nemeth's UNIX System Administration Handbook from Prentice Hall. This book covers many issues and will give you a starting point. However, even with its almost 800 pages, it is too broad to go into much detail of the topics it covers. There are other books that do provide detail, but which ones you should read depends on your situation. I've listed a few here, which, incidentally, are all from O'Reilly and Associates. DNS and BIND by Paul Albitz and Cricket Liu explains much of the working and configuration of the name server. Managing NFS and NIS explains many of the issues facing a system administrator who has to administrate a site using NFS and NIS. The book is now a bit dated, as it does not explain NIS+, but is still very valuable. The Sendmail Book, by Bryan Costales with Eric Allman and Niel Rickert, gives a very good overview of sendmail, how it works, and how it can be configured. Don't worry too much about the sendmail configuration rules in the beginning; the M4 configuration macros described in Appendix E will suffice in nearly all cases. Focus on getting a general understanding of how sendmail works and where the security potholes are located (in addition to the programming flaws of sendmail itself, of course). Finally, TCP/IP Network Administration by Craig Hunt gives a very good introduction to how to administrate TCP/IP networks. Unlike most other networking books, its focus is on the administration part of networking, and it more or less ignores the programming issues exactly what is needed for an emerging TCP/IP administrator.

 Q I am using OpenWindows on a Solaris system, and I would like to be able to change the title line of each window on the fly. Do you know of a utility which can do this?

 A There is no official tool I know of that can do this; however, a long time ago, in some Usenet newsgroup, somebody posted reporting an observation that printing a string to stout, starting with \033]0; and ending with \007 would put the content in between in the window header. Based on this information, I wrote the small program xhdr, which takes the local hostname followed by its list of arguments, and places it all in the header. In other words, when I execute

% xhdr this is a test

on my workstation, the header of my xterm window will change to:

baldr.sysadmin.com: this is a test

You can use this tool to play all kinds of games, for example, if you place an alias like this in your .cshrc file:

alias vi    xhdr !\* ; vi \!*; xhdr

then, when you are editing a file, you can see from the header which one it is. Before you start to add hundreds of aliases for all the commands you are using, remember that scanning the rc file takes time. So, use this with care.

 Q I need to transport large files/dirs from office to home and back. The solution I am currently attempting is to tar the information to a SCSI QIC-150 on my server at work and read it on my SCSI QIC-150 at home. Unfortunately, although writing the tape has proved easy enough, I have not been able to find any utilities that will enable me to read the tape from my PC.

The closest that I have come is a utility called WinTAR that can read/write tar onto a remote tape drive or read/write local files/floppies. The author says that reading/writing of local SCSI tape drives will not be available until Q4. Do you know of any free/share/inexpensive-ware that will run on a PC and will read/write tar (or cpio for that matter) tapes in a local SCSI drive?

 A GNU tar version 1.11.8 has support for MS-DOS systems. You might want to try that one out. You can ftp the GNU tar from:

ftp://prep.ai.mit.edu/pub/GNU/tar-1.11.8.tar.gz

As an alternative, the MKS toolkit has all the well-known UNIX utilities, but runs on MS-DOS. You can find more information at: http://www.mks.com.

 Q Are you aware of a program to run on Linux that will do billing and accounting for Shell and PPP accounts?

 A There are a number of commercial products available. The two I have heard of are AstroArch Consulting (http://www.tpoint.net/astroarch) and RTD Systems & Networking, Inc. (http://www.rtd.com). Both of these are aimed at ISP. I have never used either of these packages, so I cannot speak to the quality of them.

If you are looking for a freeware package, your best bet is probably the System Resource Accounting package for BSD-flavored systems. It was developed at University of Rochester and presented at LISA V. The sources are available from:

ftp://ftp.cc.rochester.edu/pub/acc-src/acct-4.0

I doubt that this system will fit your needs as is, but may very well be a worthwhile starting place for building the software you need.

 Q I think I remember a tool that generated graphs from data produced by sar. Does this ring any bells with you? I've done some searches using web tools and archie and posted to Usenet, but have come up blank.

I suppose I could roll my own, but I'd hate to reinvent the wheel. Any help or thoughts would be appreciated.

 A When I got this question, I remembered a utility like that in an older version of UNIX. I looked in an old UNIX System III manual and found a man page for a utility called sag or System Activity Graph. According to the man page, this utility would display, in a graphical form, the system activity of the UNIX operating system during specified time intervals. Unfortunately, I don't remember any UNIX system where this command actually was working.

Nevertheless, such a utility would be really useful. If any of our readers knows of a freeware implementation of this or a similar utility, please let me know. In the meantime, stay tuned for news.

About the Author

Bjorn Satdeva is the president of /sys/admin, inc., a consulting firm which specializes in large installation system administration. Bjorn is also co-founder and former president of Bay-LISA, a San Francisco Bay Area user's group for system administrators of large sites. Bjorn can be contacted at /sys/admin, inc., 2787 Moorpark Ave., San Jose, CA 95128; electronically at bjorn@sysadmin.com; or by phone at (408) 241-3111.