- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Can someone help me parse this file?
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
Forums
Discussions
Discussions
Discussions
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
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
05-14-2005 01:46 AM
05-14-2005 01:46 AM
1. I have a file that contains qualifiers for some tuxedo servers such as group name, server name, initial server ID, # of MIN servers & # of MAX servers (server ID range) to run.
2. Each entry in the file looks like this:
server left side
service group name after the =
Initial Server ID: 100 in this example
Minimum number to start with: 2
Maximum number to run: 8
So, tuxedo ID range would be 100-107
File extract entry:
+++++++++++++++++++++++++++++++++++++++++++
service2Svr_X0 SG=NABE1st
SRVID=100
MIN=2 MAX=8
RQADDR="service2X0Q"
SEL="-A -o /apath/appotherlog/whatservice2X0.out -h -e /apath/appotherlog/whatservice2X0.err -r -- --production --asynchistory --tuxrecloc"
+++++++++++++++++++++++++++++++++++++++++++
For the example provided above two processes (at the least 100 & 101), would need to be running, they'll look something like this (ID after the -i):
userapp 27142 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 100 -u hostXX -U /apath/app/c
userapp 27271 1 0 May 11 ttyp6 0:24 service2Svr_X0 -g 2 -i 101 -u hostXX -U /apath/app/c
I need a way to parse the file to display or extract the above information and display in a way such as this:
NOTE: ID is the initial ID only
Svr ID |Svr Grp | ID |MIN|CUR| MAX |
service2Svr_X0| NABEAPP| 100| 2 | 2 | 8 |
And then some way to process this information to discover the IDs that are already running (processes) to figure out how to startup more (let's say another two more, to create additional processes like the ones below):
userapp 27300 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 102 -u hostXX -U /apath/app/c
userapp 27357 1 0 May 11 ttyp6 0:24 service2Svr_X0 -g 2 -i 103 -u hostXX -U /apath/app/c
Or if let's say there're already 4 running and I would like to stop 1:
userapp 27142 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 100 -u hostXX -U /apath/app/c
userapp 27271 1 0 May 11 ttyp6 0:24 service2Svr_X0 -g 2 -i 101 -u hostXX -U /apath/app/c
userapp 27300 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 102 -u hostXX -U /apath/app/c
userapp 27357 1 0 May 11 ttyp6 0:24 service2Svr_X0 -g 2 -i 103 -u hostXX -U /apath/app/c
Determine the available IDs running, grab one and terminate it, to end up with:
userapp 27142 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 100 -u hostXX -U /apath/app/c
userapp 27271 1 0 May 11 ttyp6 0:24 service2Svr_X0 -g 2 -i 101 -u hostXX -U /apath/app/c
userapp 27300 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 102 -u hostXX -U /apath/app/c
More to follow, attaching an extract sample of the file in question.
Thanks,
Adam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2005 01:46 AM
05-14-2005 01:46 AM
Re: Can someone help me parse this file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2005 03:24 AM
05-14-2005 03:24 AM
Solution----- tux.p ------
$file = "tux.tmp";
$format = "%15s |%10s |%4s |%4s |%4s |%4s |%s\n";
open (TUX,"<$file") or die "COuld not open $file";
#
# Read through tuxedo config rememering params inexed by server_id
#
while (
if (/^(\w+)\s+SG=(\w+)/) {
$srv_id = $1;
$sg{$srv_id} = $2;
}
$id{$srv_id} = $1 if (/SRVID=(\d+)/);
$min{$srv_id} = $1 if (/\s+MIN=(\d+)/);
$max{$srv_id} = $1 if (/\s+MAX=(\d+)/);
}
#
# Loop through ps data looking for known server_id strings like
# userapp 27142 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 100
#
while (<>) {
if (/^\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/){
$pids{$2} .= " $1" if ($sg{$2});
$pid{"$2 $3"} = $1;
$cur{$2}++;
}
}
printf $format, qw "Svr_ID Svr_Grp ID MIN CUR MAX";
printf $format, qw "--------------- ---------- ---- --- --- ---";
foreach (sort keys %sg) {
printf $format, $_, $sg{$_}, $id{$_}, $min{$_}, $cur{$_}, $max{$_}, $pids{$_};
}
#
# And an other way to view it
#
foreach (sort keys %sg) {
print "\n";
for ($i = $id{$_}; $i < $id{$_} + $max{$_}; $i++) {
$min_text = ($i < $id{$_} + $min{$_} ) ? " (Min)" : "";
print "$_ $sg{$_} $i ", $pid{"$_ $i"}, "$min_text\n";
}
}
----- sample usage ----
ps | perl tux.p
Svr_ID | Svr_Grp | ID | MIN | CUR | MAX |
--------------- |---------- |---- | --- | --- | --- |
service2Svr_X0 | NABE1st | 100 | 2 | 4 | 8 | 27142 27271 27300 27357
service2Svr_X1 | NABE1st | 110 | 2 | | 8 |
service2Svr_X2 | NABE1st | 130 | 1 | | 3 |
service2Svr_X3 | NABE1st | 140 | 2 | | 4 |
service2Svr_X4 | NABE1st | 150 | 1 | | 3 |
service2Svr_X5 | NABE1st | 160 | 1 | | 2 |
service2Svr_X0 NABE1st 100 27142 (Min)
service2Svr_X0 NABE1st 101 27271 (Min)
service2Svr_X0 NABE1st 102 27300
service2Svr_X0 NABE1st 103 27357
service2Svr_X0 NABE1st 104
service2Svr_X0 NABE1st 105
service2Svr_X0 NABE1st 106
service2Svr_X0 NABE1st 107
service2Svr_X1 NABE1st 110 (Min)
service2Svr_X1 NABE1st 111 (Min)
service2Svr_X1 NABE1st 112
service2Svr_X1 NABE1st 113
service2Svr_X1 NABE1st 114
service2Svr_X1 NABE1st 115
service2Svr_X1 NABE1st 116
service2Svr_X1 NABE1st 117
service2Svr_X2 NABE1st 130 (Min)
service2Svr_X2 NABE1st 131
service2Svr_X2 NABE1st 132
service2Svr_X3 NABE1st 140 (Min)
service2Svr_X3 NABE1st 141 (Min)
service2Svr_X3 NABE1st 142
service2Svr_X3 NABE1st 143
service2Svr_X4 NABE1st 150 (Min)
service2Svr_X4 NABE1st 151
service2Svr_X4 NABE1st 152
service2Svr_X5 NABE1st 160 (Min)
service2Svr_X5 NABE1st 161
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2005 04:56 AM
05-14-2005 04:56 AM
Re: Can someone help me parse this file?
I can probably use this, although I wish I would have said from the beginning that I am not experienced yet with Perl and I am creating this little program with the shell (ksh in this case). However, I'll be taking my first Perl course next month and will probably convert the entire thing to perl then. However, I can probably integrate this code as part of my current shell program.
Once again, thanks for the prompt response and I am still accepting other suggestions.
Regards,
Adam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2005 06:03 AM
05-14-2005 06:03 AM
Re: Can someone help me parse this file?
I had to run earlier, so I could not add a few comments/explanations.
1) the key line while reading the tuxedo config is: if (/^(\w+)\s+SG=(\w+)/)
This regexpr detects a new server as:
^ = begin of line
(\w+) = remember a series of word characters in $1 (the serverid)
\s+SG= = some spaces, the characters SG=
(\w+) = remember the next word in $2 (the group).
The script then uses $1, the server_id, as an index to a bunch of arrays with detail values (min, max,...).
2) The line: while (<>) { reads STDIN, but you can readily make that 'live' executing the ps command there and then using the 'backtick' operator: foreach (`ps -xxx`) {
3) the next line is a touch complicated regexpr in an attempt latch on to just the right lines, and not be depend on varying time stamp formats and such. If you can trust the ps output the always have exactly those words in those placed you can replace that BLOCK with a more awk like solution:
while (<>) {
($p,$srv,$id) = (split)[1,8,12];
next unless ($sg{$srv});
$pids{$srv} .= " $p"; #append a pid
$pid{"$srv $id"} = $p; # save pid in uniq element
$cur{$srv}++; #count as a current server
}
4) with that same backtick, of system() calls, or forks, you can readily execute new commands from the perl script directly.
Enjoy perl!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 06:44 AM
05-18-2005 06:44 AM
Re: Can someone help me parse this file?
# awk -f below_script_name your_input_file > output_file_name
=============================================
#
# awk script for parsing files
#
# strops function
function strops(input, words, n)
{
n = split(input, words, "=")
return words[n]
}
# main routine
BEGIN {
RS=""; OFS="|"
print "Svr_ID| Svr_Grp|ID|Min|Cur|Max"
print "------------------------------"
} /^service/ {
print $1,
strops($2),
strops($3),
strops($4),
strops($4),
strops($5)
}
=============================================
Let me know if this script was able to meet your needs...
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 07:56 AM
05-18-2005 07:56 AM
Re: Can someone help me parse this file?
I have a bit of a problem following along your:
2) The line: while (<>) { reads STDIN, but you can readily make that 'live' executing the ps command there and then using the 'backtick' operator: foreach (`ps -xxx`) {
No idea about what you're referring to with "backtick" operator with the "foreach (`ps -xxx`).
When executing the above given example (with the file name given):
ps | perl tux.p
I only get:
mucobt10> ps | perl parseubb.pl
Svr_ID | Svr_Grp | ID | MIN | CUR | MAX |
--------------- |---------- |---- | --- | --- | --- |
Thanks for explaining again to a "non-perl" guy.
I'll give a try to your suggestion with awk sandman.
Adam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 08:32 AM
05-18-2005 08:32 AM
Re: Can someone help me parse this file?
cheers!
sandman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 09:29 AM
05-18-2005 09:29 AM
Re: Can someone help me parse this file?
For your awk I got:
awk -f
My output.file:
Svr_ID| Svr_Grp|ID|Min|Cur|Max
------------------------------
However, this is not what I am expecting, that's only the header. I would like to get an output like shown above (parse file and find processes that are running/not running per file params -- show which are running and provide IDs for those that area available to be fired up if necessary!):
Svr_ID | Svr_Grp | ID | MIN | CUR | MAX |
--------------- |---------- |---- | --- | --- | --- |
service2Svr_X0 NABE1st 100 27142 (Min)
service2Svr_X0 NABE1st 101 27271 (Min)
service2Svr_X0 NABE1st 102 27300
service2Svr_X0 NABE1st 103 27357
service2Svr_X0 NABE1st 104
service2Svr_X0 NABE1st 105
service2Svr_X0 NABE1st 106
service2Svr_X0 NABE1st 107
service2Svr_X1 NABE1st 110 (Min)
service2Svr_X1 NABE1st 111 (Min)
service2Svr_X1 NABE1st 112
service2Svr_X1 NABE1st 113
service2Svr_X1 NABE1st 114
service2Svr_X1 NABE1st 115
service2Svr_X1 NABE1st 116
service2Svr_X1 NABE1st 117
service2Svr_X2 NABE1st 130 (Min)
service2Svr_X2 NABE1st 131
service2Svr_X2 NABE1st 132
service2Svr_X3 NABE1st 140 (Min)
service2Svr_X3 NABE1st 141 (Min)
service2Svr_X3 NABE1st 142
service2Svr_X3 NABE1st 143
service2Svr_X4 NABE1st 150 (Min)
service2Svr_X4 NABE1st 151
service2Svr_X4 NABE1st 152
service2Svr_X5 NABE1st 160 (Min)
service2Svr_X5 NABE1st 161
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 09:38 AM
05-18-2005 09:38 AM
Re: Can someone help me parse this file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 10:29 AM
05-18-2005 10:29 AM
Re: Can someone help me parse this file?
strops($4),
strops($4),
strops($5)
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 05:06 PM
05-18-2005 05:06 PM
Re: Can someone help me parse this file?
>> I have a bit of a problem following along
Well
1) I had no access to a hp-ux box at the time.
2) I do not have your environment running anyway.
3) The ITRC forum stripped the spaces, so i did not get the regexp right.
To look for the owner\pid on the ps line you need to allow for initial spaces = ^\s* :
if (/^\s*\w+\s+(\d+).....
>> No idea about what you're referring to with "backtick" operator with the "foreach (`ps -xxx`).
The xxx was intended to represent whatever ps switches you use. Working example:
:
foreach (`ps -ef`) {
if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+)/) {
:
>> ps | perl tux.p
>> I only get:
That was that space problem. Full working example below. Well, it was working on my box by looking for rlogind as svr_id and tweaking the regexpr a little. Hope I fixed it right for your case.
regards,
Hein.
$file = "tux.tmp";
$format = "%15s |%10s |%4s |%4s |%4s |%4s |%s\n";
open (TUX,"<$file") or die "COuld not open $file";
#
# Read through tuxedo config rememering params inexed by server_id
#
while (
if (/^(\w+)\s+SG=(\w+)/) {
$srv_id = $1;
$sg{$srv_id} = $2;
}
$id{$srv_id} = $1 if (/SRVID=(\d+)/);
$min{$srv_id} = $1 if (/\s*MIN=(\d+)/);
$max{$srv_id} = $1 if (/\s+MAX=(\d+)/);
}
#
# Loop through ps data looking for known server_id strings like
#
## userapp 27142 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 100
##
##while (<>) {
## if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/){
foreach (`ps -ef`) {
if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/) {
$pids{$2} .= " $1" if ($sg{$2});
$pid{"$2 $3"} = $1;
$cur{$2}++;
}
}
printf $format, qw "Svr_ID Svr_Grp ID MIN CUR MAX";
printf $format, qw "--------------- ---------- ---- --- --- ---";
foreach (sort keys %sg) {
printf $format, $_, $sg{$_}, $id{$_}, $min{$_}, $cur{$_}, $max{$_}, $pids{$_};
}
#
# And an other way to view it
#
foreach (sort keys %sg) {
print "\n";
for ($i = $id{$_}; $i < $id{$_} + $max{$_}; $i++) {
$min_text = ($i < $id{$_} + $min{$_} ) ? " (Min)" : "";
print "$_ $sg{$_} $i ", $pid{"$_ $i"}, "$min_text\n";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 07:17 PM
05-18-2005 07:17 PM
Re: Can someone help me parse this file?
Using the awk script and the sample input file you provided this is what i get on my system:
# awk -f parse.awk input.txt
Svr_ID| Svr_Grp|ID|Min|Cur|Max
------------------------------
service2Svr_X0|NABE1st|100|2|2|8
service2Svr_X1|NABE1st|110|2|2|8
service2Svr_X2|NABE1st|130|1|1|3
service2Svr_X3|NABE1st|140|2|2|4
service2Svr_X4|NABE1st|150|1|1|3
service2Svr_X5|NABE1st|160|1|1|2
I'm not sure why you can only see the header line only. The awk script run as is will give you the output pasted above.
Also the strops($4) is a function embedded at the top of the awk script if you notice. This strops() function is called by the main routine.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 01:21 AM
05-19-2005 01:21 AM
Re: Can someone help me parse this file?
I agree with you that awk is a powerful and useful language. BUt I recommend it for more basic tasks and switch to perl for more complex work. After a while you might just start in perl, and it is good to be reminded of awk.
Your script solves the first part of the question. The next part woudl be harder (not impossible) in awk. For example a simple 'word split' fails on typical ps data lines because the login time can be two words (month day) or one word (hh:mm:ss). Not impossible to solve, but harder.
root 19681 600 0 May 11 pts/2 0:00 rlogind
sim 14372 14371 2 06:13:10 pts/ta 0:00 -csh
In awk the reading and parsing of the parameter fiel could neatly be done in the BEGIN section, remembering details in arrays. The main loop coudl then go over the ps data and break out pid/service/id
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 03:00 AM
05-19-2005 03:00 AM
Re: Can someone help me parse this file?
Confusion reigns here... Would you be son kind to attach the given code simply as a txt file, allowing for the "real" extra spaces to be included (replace/ommit the representation characters). I know about the problem with ITRC forums and extra spaces+tabs, which makes the inclusion of these to be misread or ommited... Which in turn causes examples not to work properly.
I have problems understanding parts of the code such as:
if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+)/) {
Is the first "^\s*" an actual space... Or two spaces? How about the "\s.*:"? Getting really confusing trying to figure these out.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 03:36 AM
05-19-2005 03:36 AM
Re: Can someone help me parse this file?
> allowing for the "real" extra spaces to be included
Sorry, deleted. But there are no spaces in the code I posted, otherwise i would have attached it,
>> I have problems understanding parts of the code such as:
>> if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+)/) {
That is indeed tricky.
Here is the regexpr breakdown.
^ = start of line
\s* = any number of spaces (0 or more)
\w = a word (username)
\s+ = one or more spaces
(\d+) = one or more digits, remembered in $1
\s = space
.* = any number of any char (greedy) untill...
:\d\d = a colon followed by two digits is seen (end of time)
\s+ = one or more spaces
(\w+) = a word, remembered in $2
If my code still does not work for you, then you would either have to attempt the perl debugger, or use the classic approach to sprinkle it with print statements like:
print "$1 - $2 - $3 - $id - $_";
Gotta run (literally: 5 miles :-),
Hein.
Is the first "^\s*" an actual space... Or two spaces? How about the "\s.*:"? Getting really confusing trying to figure these out.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 04:54 AM
05-19-2005 04:54 AM
Re: Can someone help me parse this file?
If my solution still not works it is probably a difference between the ps output in the topic and the real ps.
Adam, Could you attach some real ps output to a reply?
It ought to be so close that it would be ashame to not have it working.
Send me an Email (see my profile) with data sample if you like as this is no longer instersting to the community at large.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 05:30 AM
05-19-2005 05:30 AM
Re: Can someone help me parse this file?
I'm at work and being tied up resolving some problems (troubleshooting), but will send you an email later (after I attempt what you posted in your latest replies).
Thanks!
Adam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 06:30 AM
05-19-2005 06:30 AM
Re: Can someone help me parse this file?
Use of ps:
ps -fu
Output sample attached:
your code used this way:
ps -fu
How I have integrated your code this time (this is how it looks):
#+++++++++++++++++++++++++++++++++++++++++
$file = "
$format = "%15s |%10s |%4s |%4s |%4s |%4s |%s\n";
open (TUX,"<$file") or die "COuld not open $file";
#
# Read through tuxedo config rememering params inexed by server_id
#
while (
if (/^(\w+)\s+SG=(\w+)/) {
$srv_id = $1;
$sg{$srv_id} = $2;
}
$id{$srv_id} = $1 if (/SRVID=(\d+)/);
$min{$srv_id} = $1 if (/\s+MIN=(\d+)/);
$max{$srv_id} = $1 if (/\s+MAX=(\d+)/);
}
#
# Loop through ps data looking for known server_id strings like
# userapp 27142 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 100
# while (<>) {
# if (/^\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/){
foreach (`ps -fu`) {
if (/^\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/){
$pids{$2} .= " $1" if ($sg{$2});
$pid{"$2 $3"} = $1;
$cur{$2}++;
}
}
printf $format, qw "Svr_ID Svr_Grp ID MIN CUR MAX";
printf $format, qw "--------------- ---------- ---- --- --- ---";
foreach (sort keys %sg) {
printf $format, $_, $sg{$_}, $id{$_}, $min{$_}, $cur{$_}, $max{$_}, $pids{$_};
}
#
# And an other way to view it
#
foreach (sort keys %sg) {
print "\n";
for ($i = $id{$_}; $i < $id{$_} + $max{$_}; $i++) {
$min_text = ($i < $id{$_} + $min{$_} ) ? " (Min)" : "";
print "$_ $sg{$_} $i ", $pid{"$_ $i"}, "$min_text\n";
}
}
#+++++++++++++++++++++++++++++++++++++++++
As you had mentioned regarding awk, with the example provided above I would have experienced some issues when some of the services just recently started using time (1 field) and not date (2 fields).
Thanks, and sorry for the long delay from my end.
Adam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 06:33 AM
05-19-2005 06:33 AM
Re: Can someone help me parse this file?
Guess the awk script solves only the first part of the question. I'll attempt to solve the other half if you give a more clear explanation of what needs to be done.
BTW, Heinen thank you for pointing this out to me 'coz i thought i had it all figured out (how very ignoramus of me!!!).
Reason I don't learn Perl is because i'm good with C and tasks that cannot be done with either shell/sed/awk...i prefer to use C. Perl is an excellent language and i'm getting old to learn new tricks proverbially speaking ;->
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 07:41 AM
05-19-2005 07:41 AM
Re: Can someone help me parse this file?
I am taking a Perl course next month, so there I hope be able to work on many of the little bumps I've encountered with my current project.
Here's a summary of what I'd like to accmoplish, although this is but one component of the main task. But for this one:
1) parse the file and obtain the information as shown in my first posting (file sample is provided there too):
2) From that portion, the headers and main info is selected... To obtain a view like this:
Svr ID |Svr Grp | ID |MIN|CUR| MAX |
service2Svr_X0| NABEAPP| 100| 2 | 2 | 8 |
3) However, based on the parameters from this file and current processes (those that are running and those that are not), obtain a view like the one that Heuvel displayed:
Example: Let's concentrate only on service service2Svr_XO (from file that need to be parsed):
a. Minimum number of servers that will be running per that file = 2
b. Currently running = 2
ps output:
userapp 27300 1 0 May 11 ttyp6 0:25 service2Svr_X0 -g 2 -i 102 -u hostXX -U /apath/app/c
userapp 27357 1 0 May 11 ttyp6 0:24 service2Svr_X0 -g 2 -i 103 -u hostXX -U /apath/app/c
c. According to the information parsed from the file and what is currently running, a view like this would be obtained -- The list shows ID 100-107 (for a total max of 8), 100 and 101 show the :
Svr_ID | Svr_Grp | ID | MIN | CUR | MAX |
--------------- |---------- |---- | --- | --- | --- |
service2Svr_X0 NABE1st 100 2 2 8
service2Svr_X0 NABE1st 101 2 2 8
service2Svr_X0 NABE1st 102
service2Svr_X0 NABE1st 103
service2Svr_X0 NABE1st 104
service2Svr_X0 NABE1st 105
service2Svr_X0 NABE1st 106
service2Svr_X0 NABE1st 107
What would be great to display would also be the PID, but for the tuxedo part the "Tuxedo ID" is really what I would need.
So this would be the perfect required scenario (using the attached ps file):
Display the available ID's per whatever the file specifies (2 running, max of 8).
Svr_ID | Svr_Grp | ID | PID
--------------- |---------- |---- | ---
service2Svr_X0 NABE1st 100 27142 service2Svr_X0 NABE1st 101 27271
service2Svr_X0 NABE1st 102
service2Svr_X0 NABE1st 103
service2Svr_X0 NABE1st 104
service2Svr_X0 NABE1st 105
service2Svr_X0 NABE1st 106
service2Svr_X0 NABE1st 107
This would tell me that of the possible 8 servers that can be fired up, there are 2 running (with the proper PID shown), 6 are still available and may be fired up by user (and/or those that are running can be stopped!
I hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2005 05:23 PM
05-19-2005 05:23 PM
Re: Can someone help me parse this file?
I have re-extracted the params file, the new ps data, my perl script. Modified one line in the perl script not to execute ps, but to read STDIN and it all worked?!
I also added a debug line after the ps parse to show how that works.
Works for me. Dunno what else to say!?
Test box:
$ uname -a
HP-UX hpgsp05c B.11.11 U 9000/800 690339353 unlimited-user license
$ perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2005 10:03 AM
05-20-2005 10:03 AM
Re: Can someone help me parse this file?
I also had to move the header up, since I was ending up with it at the bottom of the ps display...
from:
#foreach (`ps -ef`) {
while (<>) {
if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/) {
print "$1 - $2 - $3\n";
$pids{$2} .= " $1" if ($sg{$2});
$pid{"$2 $3"} = $1;
$cur{$2}++;
}
}
printf $format, qw "Svr_ID Svr_Grp ID MIN CUR MAX";
printf $format, qw "--------------- ---------- ---- --- --- ---";
foreach (sort keys %sg) {
printf $format, $_, $sg{$_}, $id{$_}, $min{$_}, $cur{$_}, $max{$_}, $pids{$_};
}
To:
printf $format, qw "Svr_ID Svr_Grp ID MIN CUR MAX";
printf $format, qw "--------------- ---------- ---- --- --- ---";
while (<>) {
if (/^\s*\w+\s+(\d+)\s.*:\d\d\s+(\w+) -g \d+ -i (\d+)/) {
print "$1 - $2 - $3\n";
$pids{$2} .= " $1" if ($sg{$2});
$pid{"$2 $3"} = $1;
$cur{$2}++;
}
}
foreach (sort keys %sg) {
printf $format, $_, $sg{$_}, $id{$_}, $min{$_}, $cur{$_}, $max{$_}, $pids{$_};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2005 10:48 AM
05-20-2005 10:48 AM
Re: Can someone help me parse this file?
Nah, still no good at all.
But at least I can now see that the ps output parsing is doing the right thing.
The tuxedo parameter file parsing is failing.
The input I used for that is from the attachment for "May 14, 2005 13:46:45 GMT". Please check with that as input. In the script I used 'tux.tmp' as filename. Surely you adjusted that to the right filename.
Maybe there are spaces in the real file?
If so, change: if (/^(\w+)\s+SG=(\w+)/) {
to for example: if (/^\s*(\w+)\s+SG\s*=\s*(\w+)/) {
Also check the SRVID, MIN and MAX match lines.
Send Email if need be: hein hp com
It doesn't come much easier :-).
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 06:53 AM
05-25-2005 06:53 AM
Re: Can someone help me parse this file?
I would like to make the $file value available through the command line as such:
ps -fu
Thanks for any prompt response, I've been trying to find a simple answer without much success yet.
Thanks
MAD