Operating System - HP-UX
1826055 Members
4096 Online
109690 Solutions
New Discussion

Help to re-write a perl script.

 
SOLVED
Go to solution
Reynaldo Torres
Advisor

Help to re-write a perl script.

Good morning all, and happy holidays. I would like to get some help to re-write a perl script, which currently is setup as a pager alert for some of my mount points in my UNIX HP9000 K570, but now I have the need for e-mail as well. If anyone could assist me on this, I will really appreciated, and I will give points to the best respond. The following script is the one that I have running as a pager alert. This script was written by someone else, I am not an expert writing perl scripts, so I would like to get the right syntax for it.

Thanks in advance,

RT.

#!/usr/contrib/bin/perl

# Usage: dfstat

$dfcmd="/usr/bin/bdf";
$pagepgm="/etc/pager";
$pagepin="2377725";

$warnpct=90;
$msg="";
$msgcnt=0;

open(DF, "$dfcmd|") || die "can't run $dfcmd: $!";
$title=;
#print TTYOUT $title;

# Catch any errors with eval. A bad pattern, for instance.

eval <<'EOF';
while ($buf=) {
chop($buf);
($filesys, $kbytes, $used, $avail, $usedpct, $mountpt)=split(' ', $buf);
chop($usedpct);
next if (($mountpt ne "/") && ($mountpt ne "/var") && ($mountpt ne "/usr") && ($mountpt ne "/u112") && ($mountpt ne "/tmp") && ($mountpt ne "/home") && ($mountpt ne "/u113") && ($mountpt ne "/u61") && ($mountpt ne "/u52"));
if (($mountpt eq "/") && ($usedpct > 80)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/var") && ($usedpct > 80)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/tmp") && ($usedpct > 90)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/usr") && ($usedpct > 80)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/u112") && ($usedpct > 85)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/u113") && ($usedpct > 80)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/u61") && ($usedpct > 85)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/u52") && ($usedpct > 80)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if (($mountpt eq "/home") && ($usedpct > 85)) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
next;
}
if ($usedpct >= $warnpct) {
$msg=$msg . " $mountpt $usedpct%.";
$msgcnt++;
}
}
EOF

if ($msgcnt > 0) {
$msg="Warning ora2 bdf:" . $msg;
# print "$msg\n";
&page($pagepin);
sleep 120;
&page($pagepin);
}

sub page {
open(PAGER,"|$pagepgm $_[0]") || die "Couldn't run $pagepgm: $!\n";
print PAGER "$msg\n";
close PAGER;
}


Reynaldo Torres
3 REPLIES 3
Hazem Mahmoud_3
Respected Contributor

Re: Help to re-write a perl script.

Put the following at the beginning of your script:

#Module used to send the email
use MIME::Lite;

then put the following code at the bottom, you will obviously have to tweak it so it can email you what you want. I use this script to email reports out to employees. It runs in cron. Obviously the variables defined below would need to be defined somewhere in the middle of the script. I hope this helps! If you need more help to do something more specific, just let me know.

$mime_msg = MIME::Lite->new( #setup email message
From => $from,
To => $to_address,
CC => $reply,
"Reply-To"=> $reply,
Subject => "$newfile - $subject",
Data => $message1
)


-Hazem
harry d brown jr
Honored Contributor
Solution

Re: Help to re-write a perl script.

add this (inside your error count test $msgcnt > 0):

open(tmpFILEPTR,"|uuencode text.txt |mailx -m -s'ERROR TITLE HERE' YOURNAME\@YOURDOMAIN.com") || die "ERROR MESSAGE HERE\n";

printf(tmpFILEPTR "%s",$msg);

close(tmpFILEPTR);

live free or die
harry
Live Free or Die
Reynaldo Torres
Advisor

Re: Help to re-write a perl script.

You guys are great! I really appreciate all your help. Thanks again and have a safe a happy holidays to all of you.

Reynaldo.
Reynaldo Torres