These are possible output formats for ps h -eo etime
21-18:26:30
15:28:37
48:14
00:01
How to parse them into seconds?
- Please assume at least 3 digits for the days part as I don't know how long it can be.
- The output will be
egreped
to one only line so no need for a loop.
I've implemented a 100% bash solution as follows:
Here's a PHP alternative, readable and fully unit-tested:
Works on AIX 7.1:
Pure BASH. Requires BASH 2+ (?) for the BASH_REMATCH variable. The regex matches any of the inputs and places the matched strings into the array BASH_REMATCH, which parts of are used to compute number of seconds.
Think I might be missing the point here but the simplest way of doing this is:
Note the 's' on the end of etime.
Then to run use: