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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert ps auwwg to spreadsheet

Status
Not open for further replies.

LANOPS

MIS
Oct 22, 2002
2
CA
I run a crontab every 30 minutes to with "ps auwwg >psfile.out"

I want to take the PID field and conevert that to column headers, then have the proper information fall under it for every 30 minutes.
example of date & ps auwwg
----
24aug050200
USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME cmd
root 4468 0.0 0.0 16 8892 - A Aug 03 0:00 kproc
root 4682 0.0 0.0 460 204 - A Aug 03 0:00 /usr/sbin/syslogd
root 4988 0.0 0.0 496 236 - A Aug 03 0:00 /usr/sbin/srcmstr
root 5174 0.0 0.0 72 24 - A Aug 03 0:00 /usr/ccs/bin/shlap
----
The result should look like this:
---
pid--> 4468 4682 4988 5174
date sz;rss sz;rss sz;rss sz;rss
24aug050200 16;8892 460;204 496;236 72;24
24aug050230 16;8892 460;204 496;836 72;44
24aug050300 16;8892 460;204 496;936 72;54
24aug050330 16;8892 460;204 496;636 82;64

How do I do this with awk or sed?
 
Hi

At first glance I think this is what you want. Does not reproduce the second line ( date sz;rss ... ), just the header with PID's and the data :

Code:
BEGIN {
  ORS=" "
  print "pid-->"
}
NR>1 {
  print $2
  etc=etc $5 ";" $6 " "
}
END {
  ORS="\n"
  print ""
  print strftime("%d%b%y%H%M",systime()),etc
}

But I think your theory is wrong. The processes will change between two runs, so the above is correct for only one run. Beside this, for a somehow correct representation you need a veeery wide table ( number of columns=greatest possible PID ), and most of it will be empty ( spaceholder for PIDs currently not assigned ).

Please give us some detail of what you want.

Feherke.
 
The processes ID's do not change for the apps I am monitoring. Some of them are having memory leaks, and are growing over time. It would be even better if I could specify which 16 processes I wanted to monitor, or specify which users to monitor along with the users processes.
 
Hi

So you have a list of PIDs. This was not mentioned in the question. Let me try again "

Code:
BEGIN {
[gray]# >>> settings >>>[/gray]
[gray]# lists of space separated values to filter on, or empty for all[/gray]
  user=""   [gray]# all users[/gray]
  pid="4468 4682 4988 5174"   [gray]# only enumerated PIDs[/gray]
[gray]# <<< settings <<<[/gray]
  printf strftime("%d%b%y%H%M",systime())
}
(user=="" || user~"\\<" $1 "\\>") && (pid=="" || pid~"\\<" $2 "\\>") {
  printf " " $5 ";" $6
}
END {
  print ""
}

The above code will not create the two header lines from your sample, I think that is not necessary.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top