News for hackers. Stuff that matters.
Re:PowerShell is open sourced and is available on Linux by Klathmon on Thursday August 18, 2016 @12:41PM (#12314039)
I wrote a bash script to sort processes by age on an old redhat 4 machine.

What sounded like a very simple thing, quickly ended up being a complete nightmare of bash, python, and an unholy bunch of linux commands.

It was ugly, and a terrible way of doing it, but we got it working.

It would have been amazing if i could pipe PS into something that could sort by the dates on the 4th column, and return the last column in the sorted order.

Re:PowerShell is open sourced and is available on Linux by daveloyall on Thursday August 18, 2016 @01:16PM (#12314421)
Pretty sure the section in the `ps` man page called OBSOLETE SORT KEYS indicates that even the `ps` on very old redhat machines could do this out of box... see the field `start_time`.

Failing that, consider the `etimes` field (seconds since process was started) used in conjunction with the -o feature (control output format) so you can put `etimes` up front then simple pipe the output to `sort`.

Those things being said, the situation you describe is indeed hairy. `ps` output was designed for human consumption, that's why the process age field format varies (1w vs 10:15) and that's presumably why you wanted to bring python into the mix!

...You might have had an easier time looking in /proc...

Indeed, this looks promising:

    cat /proc/[0-9]*/stat|sort -n|less -S
EDIT: hm, I don't know how old /proc is!

EDIT #2: But try doing ANY of this on an ancient Windows machine! The "peer" of your old Redhat machine would be what, a Win2k3 machine, or a Win2k? How old is PowerShell? :)

Re:PowerShell is open sourced and is available on Linux by Klathmon on Thursday August 18, 2016 @01:45PM (#12314711)
Honestly it was a quick and dirty one-time project, and I just needed to cobble something together.

I was more just commenting on the fact that with a "strongly-typed" shell some of this stuff becomes much easier without every single tool needing to add all these options.

It gets much more "Unix Philosophy" when every command doesn't need it's own sorting logic, and doesn't need it's own date display logic, and doesn't need it's own way of displaying it to the user.

It can output an object, which can be piped into another program to use what it needs which can be piped to something else to do some sorting which can pipe it out to another to display it in a nice table.

Re:PowerShell is open sourced and is available on Linux by daveloyall on Thursday August 18, 2016 @04:30PM (#12316110)
I hear you. I myself was impressed by some things PowerShell can do easily.

But let's not throw out the baby with the bathwater... The unix shell ecosystem is powerful magic. There are LOTS of things that can be done there with great ease.

Not to mention--and I understand full well that this stance is falling out of fashion--MICROSOFT ... KILLED... my PAPPY! :|

Re:PowerShell is open sourced and is available on Linux by jve on Friday August 19, 2016 @06:58AM (#12319168)
PowerShell was released after Win2k3, however you could install it on Win2k3/XP, even PowerShell 2 afterwards: https://support.microsoft.com/en-us/kb/968929
Re:PowerShell is open sourced and is available on Linux by mining on Thursday August 18, 2016 @12:59PM (#12314217)
It's entirely possible this is a recent development, but "ps -o cmd --sort etime" seems to do what you're asking for.
Re:PowerShell is open sourced and is available on Linux by Klathmon on Thursday August 18, 2016 @01:08PM (#12314326)
sadly that wasn't available, and researching an easier way to do it without that was met with pages and pages of people saying to do that...
Re:PowerShell is open sourced and is available on Linux by dangerlibrary on Thursday August 18, 2016 @01:08PM (#12314329)
There's literally an example in 'man ps' that does exactly this. It's right there in the output formatting section.

    ps kstart_time -ef
Re:PowerShell is open sourced and is available on Linux by PeCaN on Thursday August 18, 2016 @12:41PM (#12314045)
You could probably hack something together with awk, but this sort of thing is exactly why I like powershell a lot.
Re:PowerShell is open sourced and is available on Linux by Klathmon on Thursday August 18, 2016 @12:52PM (#12314141)
Yeah i ended up using awk, some python for the date parsing and sorting, back to bash for grep and another thing i can't remember, then into the program that actually needed the data.

It was a mess, and I remember thinking it would be such a simple thing that was so much more complicated than i thought it would be.