HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help to re-write a perl script.
Operating System - HP-UX
1826055
Members
4096
Online
109690
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2003 02:39 AM
12-23-2003 02:39 AM
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;
}
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
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2003 03:19 AM
12-23-2003 03:19 AM
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
#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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2003 03:44 AM
12-23-2003 03:44 AM
Solution
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2003 04:11 AM
12-23-2003 04:11 AM
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.
Reynaldo Torres
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP