Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Function Execution

Status
Not open for further replies.

gnikol1

IS-IT--Management
Jan 30, 2002
29
EU
I would like to execute sar from perl scripts and read the output. Ok for the execution How can I control the output of the execution with <STDOUT>?
 
The following will store the output from sar in the string $Out.

$Out = `sar`;
 
or....

open(SAR, 'your sar command|');
while(<SAR>){
# now process the output of sar one line at a time.
} Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
and how do I parse the output. What is the character delimiter?
 
OK -- that depends on the options you are giving to sar when you run it.

If you'd like to post a few lines of that output I'm sure that I, or someone else here, would be able to get you going with a perl script to process it. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
HP-UX daphne B.11.00 A 9000/800 02/13/02

12:07:37 %usr %sys %wio %idle
12:07:38 0 0 1 99

What I would like to know is waht is the CR and LF ASCII nums. What I thing I will do is:
@data=split /$CR$LF/,sar
Read the @data[3]
e.g. usr=split /<4 space chars>/,@data[3]

It is correct?

 
Ok - getting there, but not quite

first of all, we don't care about the title line, so we can just reject that

Next - we split up the data line into some variables

Like this, with the open bit from my previous post

while(<SAR>){
next if /usr/; # reject title line
($tm,$usr,$sys,$wio,$idle) =
split(/\s+/);
# and now do something with the data
}

the split() function chops up the line based on spaces (that's the /\s+/ bit)

with me?

If you are, what is it you'd like to do with this data? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks a lot
I have another question. How do I use perl headers....
 
not sure what you mean by perl headers Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
this is my thread for the perl headers.


thread219-211316 it is not important..


Thanks a lot for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top