Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 12th, 2004, 3:29 PM   #1
akilhoffer
Newbie
 
Join Date: Sep 2004
Posts: 3
Rep Power: 0 akilhoffer is on a distinguished road
I need to write a shell script that gathers performance statistics such as CPU utilization, memory usage, pf usage, disk, etc. and format the results in an XML file. My problem is (besides being new to Linux/Unix) I don't know how to gather this information in a format suitable to re-format into XML. I know about the 'top' command, but wouldnt know how to programatically extract this information. Does anyone out there have any sample scripts that do something similar? Thanks in advance to anyone who points me in the right direction!

-Tony
akilhoffer is offline   Reply With Quote
Old Sep 13th, 2004, 2:59 AM   #2
erebus
Programmer
 
erebus's Avatar
 
Join Date: Aug 2004
Location: /dev/null
Posts: 65
Rep Power: 4 erebus is on a distinguished road
Send a message via AIM to erebus
Redirecting the output of 'top' to another steam would be the solution. Something like
$ top > file
would definately work. You could then use this file for your XML work, or extract what you need using something like Awk or Perl, then do what you must with that. Hope I understood your problem.
__________________
<span style='font-size:14pt;line-height:100%'><span style='color:red'>&quot;Political power grows out of the barrel of a gun&quot; - Mao Tse-Tung</span></span>
erebus is offline   Reply With Quote
Old Sep 13th, 2004, 8:42 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,453
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
That is the definitely the way I do similar scripts. Redirect the program's output to a file... within the same script, read that file back in using Sed or Awk, line by line... assigning values to variables where needed and output the XML formatted variables and values to another file, then deleting the temporary file.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Sep 13th, 2004, 8:52 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
top is the way to go man, it'll tell you everything you want to know.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Sep 15th, 2004, 2:44 PM   #5
akilhoffer
Newbie
 
Join Date: Sep 2004
Posts: 3
Rep Power: 0 akilhoffer is on a distinguished road
Thanks, everyone. That was very helpful! Top was definitely the way to go.
akilhoffer is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC