UNIX Hints & Hacks

ContentsIndex

Chapter 4: System Monitoring

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

4.1 Monitoring at Boot Time

 

4.5 Mail a Process

 

4.9 Monitoring with ping

 

4.2 Starting with a Fresh Install

 

4.6 Watching the Disk Space

 

4.10 Monitoring Core Files

 

 

4.3 Monitor with tail

 

4.7 Find the Disk Hog

 

4.11 Monitoring Crash Files

 

 

4.4 Cut the Log in Half

 

4.8 Watching by grepping the Difference

 

4.12 Remember Daylight Savings Time

 

 

 

4.5 Mail a Process

4.5.1 Description

4.5.1 Description

As processes or tasks are being monitored, one of the easiest forms of notification is email.

Example One: Piping mail

Flavors: AT&T, BSD

Shells: All

Syntax:

[command|script] | mail [-s subject] address
[command|script] | Mail [-s subject] address

You can execute a command or script and pipe the output to the mail command. A manual or scripted process takes the output from a command or script and writes it to a file. Then run the mail command, read the file into it, and send the contents off to an email address.

# tail -20 /var/adm/suslog > /tmp/sulog
# mail admin@rocket.ugu.com
Subject: Root Access
~r /tmp/sulog
.
# rm /tmp/sulog

This entire process can be replaced by piping the command into mail:

# tail -20 /var/adm/sulog | mail -s "Root Access" admin@rocket.ugu.com

The result is the last 20 lines from the file that record who logged in as superuser and mail the information to the system administrator.

The crontab can also be set up to schedule a job and pipe any results out to mail. This notifies an administrator when something might potentially have gone wrong with a scheduled backup. The backup script backmeup simply tars all the files in the partition called /usr2.

#! /bin/sh
tar -cf /dev/rst8 /usr2

Line 1: Define the shell.

Line 2: Create a tar archive of the partition to a tape device.

5 2 * * * /usr/local/bin/backmeup | mail -s "rocket Backups" admin@rocket.ugu.com

When the scheduled cron jobs run at 2:05 a.m. the program backmeup runs. If any errors occur during the process, the administrator is notified in the form of an email message.

Example Two: Redirecting mail

Flavors: AT&T, BSD

Shells: All

Syntax:

mail [-s subject] address < file
Mail [-s subject] address < file

While monitoring a system, informational files sometimes get created. If these need to get mailed, a file can be redirected into mail.

# mail -s "Monitoring Results" admin@rocket.ugu.com < /var/log/monitor.log

Reason

If mail is configured on the UNIX workstation or server and is not on an isolated network, it is a perfect tool to monitor the system.

Real World Experience

Today, mail is commonly used by many UNIX administrators who have many servers and workstations at their sites to help in monitoring their systems. There are a few ways to use this method of notification:

Mailing Lists   Mail the information to a mailing list that sends the information off to multiple admins. Set up an entry into the mail alias file similar to

admins: bill@ugu.com, paul@ugu.com, gloria@ugu.com

Paging server   Commercial software is available that sends pages to a text or numeric pager via an email message. The software runs on a server that has inbound mail configured. When the software receives the mail, it dials a preset phone number that is available through the paging service that you have an account with. When it establishes a connection, the mail message passes through the paging service and you receive the message. Email addresses are generally in the form steve.mesh@pager.ugu.com or smesh.pager@rocket.ugu.com and the mail is automatically processed by the server when it is received.

Paging Service  With the advancement of the Internet, some companies that provide paging services also provide a means of emailing a message directly to your pager through their servers. This method does have advantages and disadvantages. One advantage is that the service generally doesn't cost anything extra. Another advantage is that you don't have to purchase any extra software for your server, a real money saver for you. The disadvantage is the number of points-of-failure in getting the email message to the paging service. The message could travel through any number of computer systems to reach the destination host. Your email message could get delayed or bounced. A general email address with this method can take the form [pin]@pageserver.com or 5558919@skymail.com.

If you monitor the same thing on all your machines and they all generate some type of report, you might want to email everything from one spot. Collect the data from all the remote machines via NFS mount points or via FTP at a given time. Then email all the small files, or parse them together into one large systems report from one mail server.

You might want to set up a back-up plan. When I monitor my systems, I test to make sure that the remote mail forwarding host and the default router is up first. If not, I have a modem configured on the local mail host to notify me via pager that there is a bigger problem.

Other Resources

Man pages:

mail, Mail

WWW:

http://www.ugu.com/sui/ugu/show?vendors.software.pagers

UNIX Hints & Hacks

ContentsIndex

Chapter 4: System Monitoring

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

4.1 Monitoring at Boot Time

 

4.5 Mail a Process

 

4.9 Monitoring with ping

 

4.2 Starting with a Fresh Install

 

4.6 Watching the Disk Space

 

4.10 Monitoring Core Files

 

 

4.3 Monitor with tail

 

4.7 Find the Disk Hog

 

4.11 Monitoring Crash Files

 

 

4.4 Cut the Log in Half

 

4.8 Watching by grepping the Difference

 

4.12 Remember Daylight Savings Time

 

 

 

© Copyright Macmillan USA. All rights reserved.