Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1370
  • Last Modified:

Process monitor ps output format

"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
vinod
Asked:
vinod
  • 4
  • 3
1 Solution
 
Jan SpringerCommented:
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
 
vinodAuthor Commented:
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
 
Jan SpringerCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vinodAuthor Commented:
Strange, ps auxw gives me MMMDD, not MMM DD, I want MMMDD for ps -ewo too.
0
 
Jan SpringerCommented:
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
 
vinodAuthor Commented:
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
 
Jan SpringerCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now