- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl Script.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
тАО11-26-2001 11:55 AM
тАО11-26-2001 11:55 AM
I have a perl script that I have written and the functionality works great, but I would like to add to the functionality, make it more automated. How do I in perl pars all files in a directory. Here is the perl script..
#!/usr/bin/perl -w
###############################################################
# summary_parser.pl
# Description:
# This script is intended to parser through a summary report,
# gathering start, end and interval times, to insure that the,
# interval time is within the allowable timeframe. In the event of
# the interval being not acceptable, or the CPU capture ratio being
# unacceptable, this script will email the interested parties.
################################################################
#################### VARIABLES #################################
$ACCEPTABLE_INTERVAL=1000;
$CTR=0;
#$EMAIL_LIST="me\@me.com";
$ERROR_MSG="Data is incomplete";
$SUMMARY="/var/best1/eds_dbc/Oct-14-2001.00.15_eds_dbc.ant";
$LOWER_CAPTURE=.8;
$UPPER_CAPTURE=1.8;
#################### BODY ######################################
#OPEN THE SUMMARY FILE TO READ FROM.
open (SUMRY_FILE,"$SUMMARY") ||
die "Can't Open $SUMMARY";
### READ THE LOGFILE INTO AN ARRAY OF WORDS.
while (
### COLLECT THE DATA WE NEED.
foreach $x (@ARRAY) {
if ($x eq "Resulting") {
$START_TIME=(substr($ARRAY[$CTR+7], 0,2)*60*60)+(substr($ARRAY[$CTR+7], 3,2)*60)+ (substr($ARRAY[$CTR+7], 6,2));
}
elsif (($x eq "End")&&($ARRAY[$CTR-1] ne "Collect")) {
$END_TIME=(substr($ARRAY[$CTR+5], 0,2)*60*60)+ (substr($ARRAY[$CTR+5], 3,2)*60)+ (substr($ARRAY[$CTR+5], 6,2));
}
elsif ($x eq "Interval") {
$INTERVAL = "$ARRAY[$CTR+3]";
}
elsif ($x eq "Capture") {
$CAPTURE = "$ARRAY[$CTR+2]";
}
$CTR++;
}
### CHECK TO SEE IF THE DATA IS BAD.
if (($START_TIME+$END_TIME - $INTERVAL > $ACCEPTABLE_INTERVAL) || ($CAPTURE < $LOWER_CAPTURE) || ($CAPTURE > $UPPER_CAPTURE)) {
print "\tStart Time: $START_TIME\n+\tEnd Time: $END_TIME\n-\tInterval: $INTERVAL \n=\t\t ".($START_TIME+$END_TIME - $INTERVAL);
print "\n\nCpu Capture Ratio = $CAPTURE\n";
print "\nDATA IS INCOMPLETE FOR $SUMMARY!!!\n";
##NOTIFY THE INTERESTED PARTIES.
$server = `uname -n`;
chomp $server;
$stamp=`date +%y/%m/%d`;
chomp $stamp;
$text = "Data is incomplete";
$msg="$server $stamp $ERROR_MSG";
-----------------------------------------------
Please note the $SUMMARY variable, I am having problems trying pars all files in a directory. I am stumped.
Thanks.
ct
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2001 12:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2001 12:44 PM
тАО11-26-2001 12:44 PM
Re: Perl Script.
The easy way is to make most of what you have eith a subroutine that expect the full pathname as a parameter. Something like this:
$Dirname = "var/best1/eds_dbc";
opendir(D1,$Dirname)
or die "Opening $Dirname $!\n");
my @arry1 = grep /\.ant$/, readdir(D1);
closedir(D1);
chomp(@arry1);
my $i = 0;
while ($i <= $#arry1)
{
$my fullname = sprintf("%s/%s",$Dirname,$arry1[$i]);
printf("Processing %s\n",$fullname);
# call your subroutine here
++$i;
}
I am assuming that .ant is your desired suffix.
That should do it, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2001 12:48 PM
тАО11-26-2001 12:48 PM
Re: Perl Script.
or die "Opening $Dirname $!\n";
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2001 02:06 PM
тАО11-26-2001 02:06 PM
Re: Perl Script.
what do you mean by:
printf("Processing %s\n",$fullname);
# call your subroutine here
++$i;
}
"call your subroutine here"??
Thanks,
ct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2001 02:54 PM
тАО11-26-2001 02:54 PM
Re: Perl Script.
What I meant was that I wanted for you to turn all of your existing script into a perl sub that expects 1 argument - the full pathname to the file that you wish to parse.
e.g.
sub myparser
{
my $SUMMERY = $_[0];
...
...
...
}
You would then call it in the while loop like:
myparser($fullname);
Plan B.
Modify your existing script to parse the command line to get the fullname as the first arg. You then call that perl script from within the perl script containing the loop.
e.g.
my $cmd = sprintf("perl myscript.pl %s",$fullname);
system($cmd);
Plan B is much less efficient!
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2001 03:04 PM
тАО11-26-2001 03:04 PM
Re: Perl Script.
If I could assign a million points to you, I would!
ct