Solved

Process monitor ps output format

Posted on 2008-06-22
9
1,350 Views
Last Modified: 2013-12-16
"ps auxw" lists too many fields and in an order I do not need/like.
So, I use "ps -ewo user,pid,nice,pcpu,pmem,time,start,cmd"
which works fine except that start time is in an impractical format e.g. "11:03:06" or "Jun 16" The problem with this is that I get one or two words which makes difficult to pass ps output to a script. "ps auxw" start time format is good e.g. "11:03" or "Jun06". How do I use "ps -ewo" to output a compact start time format like "ps auxw"?

Vinod
0
Comment
Question by:vinod
  • 4
  • 3
9 Comments
 
LVL 28

Expert Comment

by:Jan Springer
ID: 21841529
I would say that when you hit sixth field, perform a check as to whether the first character is alpha or numeric.  If alpha, the script would read the next field as part of the date/time.
0
 

Author Comment

by:vinod
ID: 21841607
Smart idea! I will do it if there is no alternative. But, it is not that ps does not know how to print compact time format. It does when I do "ps auxw"
0
 
LVL 28

Expert Comment

by:Jan Springer
ID: 21841678
When I do both commands on my linux machine, if the date of the process is today, I will see the format of 00:00:00 and if the date is not today, I will see MMM DD.

It's an issue as to whether the process has today's date or is from a previous date (much like an "ls -l" will show if the file is from the current year vs previous year).
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:vinod
ID: 21842147
Strange, ps auxw gives me MMMDD, not MMM DD, I want MMMDD for ps -ewo too.
0
 
LVL 28

Expert Comment

by:Jan Springer
ID: 21842186
My bad.  Yes, it's MMMDD.  I think you may still be stuck parsing the characters to determine whether to grab the following field for the date or not.
0
 

Author Comment

by:vinod
ID: 21856005
Since ps is able to print start date/time in compact format as in ps auxw, I don't see any reason it is unable to do the same for ps -ewo. I am willing to use other variations of ps as long as I can choose fields, one word/field and their order. I can't believe that authors of ps would print non-determinable number of words only to frustrate script writers.

Any taker at 200 points?
0
 
LVL 28

Accepted Solution

by:
Jan Springer earned 200 total points
ID: 21856090
Your only other option is to use auxw, read in all fields and ignore the fields that you aren't interested in if you can do without the nice field.  It's a quick perl script.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now