-
November 8th, 2003, 12:58 PM
#1
Letting shell scripts do it for you
This doesn't qualify as any sort of tutorial, just wanted to pass on a quick-tip to those who can get something
out of it.
Background: The job of system administration if done properly is an almost overwhelming task. If you aren't already
pretty handy with writing shell or Perl scripts, this would be a great time to start learning; the time and sanity gained
by automating those little time consuming bits away will reward you every day if done properly.
The example script shown here monitors disk space on the filesystem. It checks each filesystem for a percentage
used, and if the percentage is greater than the specified amount, it fires off whatever command you
choose ( in this case a home grown paging program ) to alert you of the issue. On my systems I run this as a
cron job every 5 minutes on the heavy load boxes, and every 30 minutes on light load machines.
Commands used in this example shell script: df, grep, echo, cut, awk, uname
Code:
#! /bin/sh
#
# Run from crontab to keep a close eye on disk usage
#
# --spurious
df -kl | grep -iv filesystem | awk '{print $6" "$5 }' | while read LINE;
do
PERC=`echo $LINE | cut -d"%" -f1 | awk '{ print $2 }'`
if [ $PERC -gt 96 ]; then
# replace tpage with your command, such as /usr/bin/mail, and
# spurious with the username you want the alert sent to.
/usr/local/sadm/tpage spurious WARNING $LINE on `uname -n` is $PERC percent full
fi
done
An example page (or email as the case may be) would look like
Code:
WARNING /usr/export/cvsroot on jupiter is 97 percent full
Check out the man page for sh (probably bash on Linux) for more on shell scripting. Anything you want to
monitor on a Unix system can be constructed into simple shell (or Perl) scripts and
run from cron. Just think of all the extra time you'll have for reading A.O. and making proper use of that
season lift ticket.
-- spurious
Get OpenSolaris http://www.opensolaris.org/
-
November 9th, 2003, 04:48 AM
#2
gay yawn
how about we talk about security for a chang. this post suckz!
~\G/~
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|