473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Help in Perl script (newbiew)

The soruce is the url to get the status of the server page
Output is as following between lines
------------------------------------------------------------------------------------------
Apache Server Status for test01

Server Version: IBM_HTTP_Server
Server Built: Apr 7 2003 13:38:46

Current Time: Tuesday, 19-Aug-2008 16:11:09 EDT
Restart Time: Sunday, 17-Aug-2008 07:44:21 EDT
Parent Server Generation: 0
Server uptime: 2 days 8 hours 26 minutes 48 seconds
Total accesses: 980721 - Total Traffic: 3.9 GB
CPU Usage: u25654.1 s5329.57 cu0 cs0 - 15.2% CPU load
4.83 requests/sec - 20.2 kB/second - 4285 B/request
6 requests currently being processed, 69 idle workers

------------------------------------------------------------------------------------------
I can get abve ouput in variable

I want to grab the underline and bold values in 4 variables and print those on screen

Thank you in advance.
Alex
Aug 19 '08 #1
7 1170
eWish
971 Expert 512MB
What have you tried? How much perl do you know. Please show use the code.

--Kevin
Aug 19 '08 #2
I know the khs, I understand programming but very basic perl.

my code

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #
  3. $output = `wget -q -O- --bind-address=localhost http://test:64999/server-status`; || die "Problems: $!"
  4. $output =~ /CPU Usage: u/;
  5. print "$1 ";
I tried for 1 value to print but no output on the screen.
If I get this working I'll try more in perl.

TIA

What have you tried? How much perl do you know. Please show use the code.

--Kevin
Aug 20 '08 #3
Ganon11
3,652 Expert 2GB
I know the khs, I understand programming but very basic perl.

my code

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #
  3. $output = `wget -q -O- --bind-address=localhost http://test:64999/server-status`; || die "Problems: $!"
  4. $output =~ /CPU Usage: u/;
  5. print "$1 ";
I tried for 1 value to print but no output on the screen.
If I get this working I'll try more in perl.

TIA
You're trying to print $1, but you haven't captured anything in the previous regexp. In fact, your regexp on line 4 doesn't do anything except match for "CPU Usage: u", and doesn't capture, change, or affect anything else.

Also, the "|| die" portion of your assignment in line 3 is after a semicolon, which should be giving you syntax errors (or would be if you had use strict and use warnings enabled).
Aug 20 '08 #4
eWish
971 Expert 512MB
Currently you are not capturing the data in your regex. If you want to capture then you will need to use a set of ().

Expand|Select|Wrap|Line Numbers
  1. $output =~ /(CPU Usage: u)/;
  2. print $1;
I would suggest that you check out perlre.

--Kevin
Aug 20 '08 #5
thanks, I'll read the link you posted, meanwhile if you could pls show how to do for 1 var and then I'll try for others.

TIA
Aug 20 '08 #6
eWish
971 Expert 512MB
Here is an example to help you get started. In this example I am opening a file and reading it line by line and looking for a match according to the regex. If it finds a match then print it what was captured in $1.

Expand|Select|Wrap|Line Numbers
  1. open(my $FILE, '<', $test_file) || die "Can't open $test_file: $!\n";
  2. while(<$FILE>) {
  3.     chomp;
  4.     print $1 if /^(CPU Usage:.*?\w\d{4}.\d)/g;    
  5. }
  6. close($FILE);
Since regular expressions are not my strong point someone may point out a better solution.

--Kevin
Aug 20 '08 #7
Thanks I'll try in the morning.

Here is an example to help you get started. In this example I am opening a file and reading it line by line and looking for a match according to the regex. If it finds a match then print it what was captured in $1.

Expand|Select|Wrap|Line Numbers
  1. open(my $FILE, '<', $test_file) || die "Can't open $test_file: $!\n";
  2. while(<$FILE>) {
  3.     chomp;
  4.     print $1 if /^(CPU Usage:.*?\w\d{4}.\d)/g;    
  5. }
  6. close($FILE);
Since regular expressions are not my strong point someone may point out a better solution.

--Kevin
Aug 20 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sandman | last post by:
The subject says it all. I am doing a: I have a perl script in which I am using a ReadParse routine that parses the $ENV{'QUERY_STRING'} or $ENV{'CONTENT_LENGTH'} which are two variables passed...
7
by: Dennis Roberts | last post by:
I have a script to parse a dns querylog and generate some statistics. For a 750MB file a perl script using the same methods (splits) can parse the file in 3 minutes. My python script takes 25...
1
by: Robert V | last post by:
Hi all, I could use some help programming on of my Perl script to handle different submit buttons within the same form. Here is what I have so far. A user goes to a Web form and inputs some data...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
2
by: James Hull | last post by:
Hi All: I am new in the Perl world. So far I have installed cygwin and Perl 5.8.0 along with Perl DBI and DBD::Oracle modules. NowI am trying to install Perl Tk on my PC (Windows 2K). I have...
1
by: Julia Bell | last post by:
I would like to run the same script on two different platforms. The directory in which the script(s) will be stored is common to the two platforms. (I see the same directory contents regardless...
3
by: FLOTServer | last post by:
Here's my problem: I run a gameserver that runs the game "Medal of Honor". On the game server is log file which contains all of the data from the players for that day (kills, deaths, etc...). I...
1
by: roadbai | last post by:
Hi all, This is the first time to post question here, hopefully experts of perl here can give me a hand, to be honest, I am kind of new to perl, and I am struggling with the "Out of memory" issue I...
2
by: MK | last post by:
Hello, I am new to XML and PERL and I have a few questions the answers to which I need to complete a project. All your time and effort would be highly appreciated. I have to make a small HTML page...
3
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.