How to print prstat -Z output into a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print prstat -Z output into a file?
# 1  
Old 01-03-2012
Question How to print prstat -Z output into a file?

Hi Expert,

I want to print CPU and Memory utilization into a text file. I am using "prstat -Z" to see the output on screen. When I run below command
Code:
prstat -Z | grep httpd | awk '{print$3} '>> output.txt

but it is not printing to file. Also I want to be below header on output
Code:
PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
6809 httpd 2229M  966M sleep   59    2   0:08:34 0.1% java/67

If anyone have solution for this, I will be appreciate

Thanks in advance!
Lalit


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-03-2012 at 11:18 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-03-2012
Presumably your example is the output from "prstat -Z" to the screen.
What do you need the output to look like?

What you you get in "output.txt" on your test?
# 3  
Old 01-03-2012
Okay, so Lalit, a couple of issues here:

This will never work. At least never give you what you (say) you want. 'prstat' is continuous and a single pipe allows termination for the fwrite() but the second pipe will hold all output to that process. Sorry, it's the way it works. Also your awk command would never give the data line you show that you want.

A suggestion?

Code:
#!/bin/bash
trap "exit 0;" SIGINT SIGTERM
prstat -Z 1 1 | head -1 > filemon.header
cat filemon.header > filemon.out
while [ 1 ]
do
        prstat -cZ 1 20 | grep zpool > filemon.tmp
        cat filemon.tmp >> filemon.out
        clear; date; cat filemon.header
        cat filemon.tmp | tail -21
done

Naturally, replace 'zpool' with 'http' or 'httpd' and YES, I know you actually get multiple "cycles" of output per screen, have to wait 20 seconds at first, etc., but we make do with the tools we have.

Regards

dc++
# 4  
Old 01-04-2012
Hi

Thanks for reply!

When I run this script, it creates filemon.out, filemon.header, and filemon.tmp files.
Also running continuously with header like below
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP

and no out put is coming and printing to file.

Because I am new in scripting. So there is anything else required.

Actually, My requirement is to capture the CPU and Memory utilization.
So any other option is fine or not.

Thanks
Lalit

Last edited by lalit kumar; 01-04-2012 at 10:14 AM..
# 5  
Old 01-04-2012
Again, did you change "zpool" to "httpd" ???

Just a thought...
# 6  
Old 01-05-2012
Hi

Thanks for reply
Now I am getting output in file.
But I have doubt, when I run the script then script is running and running ........not stopping and output is adding and adding.......... at end of the file.

So I have to print output 1 time only and script should break once it finish.
I am really appreciate.

Thanks!
Lalit
# 7  
Old 01-05-2012
Lalit,

Yes, the script is indeed running exactly as I wrote it. It was an example of how to use the prstat command and get results back.

Modify it as you require.

I would think if you just wanted one set of output, you would do:

Code:
 
prstat -cZ 1 20 | grep httpd > prstat.out

and then you have the information for that interval in the file.

Good luck!

dc++
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Hide output of a certain file on print

Im trying to print /etc/passwd with a variable connecting to /etc group/ But when im trying to print the output, /etc/group is printing also. Can i ask for help on what command to use so it will ignore /etc/group and only print /etc/passwd. here's the sample script. pages number and the /10... (2 Replies)
Discussion started by: joonisio
2 Replies

2. Solaris

How to output the prstat into table and send through email?

Hi how to send below prstat script output into table format and send through email? prstat|awk '{ if ($9 >= 5) print $0 }' (17 Replies)
Discussion started by: tharmendran
17 Replies

3. Shell Programming and Scripting

Format Top and prstat command output

need help with formatting output of command top and prstat. My requirment is to remove few columns and display remaining . But when i used awk to do that the output seems to be have gone vague, mixing the column values. After using awk to print particular column the output seems to have lost... (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

Output of prstat for 60 secs

Hi, I want to fire the prstat command which should run fro 60 secs and get the report into a text file using a script. I just know the command: prstat -c >> log.txt which will run until we stop it. But i want the script to run only for 60 sec,print the output to text file and stop... (3 Replies)
Discussion started by: nessj
3 Replies

6. Shell Programming and Scripting

prstat output

hi all, have a ksh script where i am doing a prstat -m -u osuser 1 1 >> $FILE_NAME but for some reason it only writes 15 lines wheres when i run the same command manually from command prompt it prints out 60 lines. why is it not writing the full 60 lines to the file ?? ta. (1 Reply)
Discussion started by: cesarNZ
1 Replies

7. Shell Programming and Scripting

print out a line from a output file

I am trying to have a script ping all the clients then output it to a file so I know which clients are off then have the next script pull the ones that are online and reboot them. This is what I am running with right now. If there is something KISS then by all means please let me know. ... (3 Replies)
Discussion started by: deaconf19
3 Replies

8. Solaris

prstat output

Can someone please explain me the "TIME" field of the output of "prstat -p<pid>" command ? The man page says it is "The cumulative execution time for the process". Does it mean how many hrs:min:sec the process is running ? If so then I'm not getting the desired output. Can someone pls help me in... (5 Replies)
Discussion started by: senabhi
5 Replies

9. Shell Programming and Scripting

prstat output in GB

Hi, Is there any way by which the unit of size and rss will be only GB while I am running the prstat command? (2 Replies)
Discussion started by: King Nothing
2 Replies

10. Shell Programming and Scripting

Redirect the output of prstat

Hi, How to redirect the output of prstat command to a file. Ex: I want to do like this while : do prstat >> prs.log sleep 5 done is it possible ???? if No, then how can i proceed?? PLEASE HELP ME OUT FROM THIS :confused: Thanks in advance ----------- (2 Replies)
Discussion started by: vastare
2 Replies
Login or Register to Ask a Question