# Appendix C

| # Creating a Script That Sends an Alert Message or RSC Event

> You can embed the `rscadm` subcommand `send_event` in a script or command file to log a Remote System Control (RSC) event or send an alert when certain conditions occur. Use the `-c` option to send an alert.

> This appendix provides an example Perl script file named `dmon.pl` that sends an RSC alert when a specified disk partition exceeds a specified percent of its capacity. This script is written for use with a Sun FireTM 280R server. To use this script as intended, submit a separate entry to the `crontab` utility for each disk partition you want to monitor.

> #!/usr/bin/perl
> # Disk Monitor
> # USAGE: dmon <mount> <percent>
> # e.g.: dmon /usr 80
> @notify_cmd = `/usr/platform/SUNW,Sun-Fire-280R/sbin/rscadm';
> if (scalar(@ARGV) != 2)
> {
> print STDERR "USAGE: dmon.pl <mount_point> <percentage>\n";
> print STDERR " e.g. dmon.pl /export/home 80\n\n";
> exit;
> }
> open(DF, "df -k|");
> $title = <DF>;
> $found = 0;
> while ($fields = <DF>)
> {
> chop($fields);
> ($fs, $size, $used, $avail, $capacity, $mount) = split(` `, $fields);
> if ($ARGV[0] eq $mount)
> {
> $found = 1;
> if ($capacity > $ARGV[1])
> {
> print STDERR "ALERT: \"", $mount, "\" is at ", $capacity,
> " of capacity, sending notification\n";
> $nofify_msg = `mount point "`.$mount.'" is at `.
> $capacity.' of capacity';
> exec (@notify_cmd, `send_event', `-c', $nofify_msg)
> || die "ERROR: $!\n";
> }
> }
> }
> if ($found != 1)
> {
> print STDERR "ERROR: \"", $ARGV[0],
> "\" is not a valid mount point\n\n";
> }
> close(DF);

Copyright © 2001 Sun Microsystems, Inc. All Rights Reserved.