0

I am writing a portable shell script to get system process information, I need process id, command, pwdx (linux). On linux I am able to get this information as follows.. but it fails on all other unix flavours.

 $ ps -awwwwwww -u <userid> -o pid,cmd|grep -i <filter_term> | egrep -v grep
 $ pwdx <pid>

what I should use on AIX, HPUX and Solaris to get the similar information, or there any cross platform command

On Solaris I have tried /usr/ucb/ps but that support formatted output and lsof for pwdx equivalent but that also doesn't show what I need

j0k
  • 22,600
  • 28
  • 79
  • 90
DevC
  • 7,055
  • 9
  • 39
  • 58
  • Jim, I looked on Google and IBM developer works, but I didn't find anything equivalent for "ps -o cmd" .. so at last posted here .. help will be appreciated – DevC Apr 19 '12 at 05:07
  • It would have been helpful for you to show what you have tried in your post (for future reference, ALWAYS show what you have tried). – Jim Garrison Apr 19 '12 at 05:14
  • Please show a sample of what output you want in addition to the way you get it on linux. – jlliagre Apr 19 '12 at 06:20

3 Answers3

2

On Solaris I have tried /usr/ucb/ps but that support formatted output:

What is wrong with formatted output ?

and lsof for pwdx equivalent but that also doesn't show what I need.

That doesn't make sense. pwdx is a Solaris native command and was even originally implemented on that OS.

jlliagre
  • 29,783
  • 6
  • 61
  • 72
0

Linux != Unix. And in the same hand, the commands are not always going to be the same, for instance GNU ps is not like Solaris ps or HP-UX ps etc. In some cases the Vendor Unix flavors offer a "compatibility binary" like those stashed in /usr/ucb on solaris. But ultimately you need to look at the man page for each version and review the output format options.

Edit. That is for in general all commands. Including grep, egrep etc.

Aaron
  • 1
  • 1
0

To show the full command name, use this

ps -eo comm

This will show the command that was run. (ps is from /usr/bin on my Solaris system 5.11)

DGM
  • 76
  • 5