dbadmin has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am very new to perl. I have a script which needs some java process running in the UNIX server. One part of the script uses perl and it executes good in HPUX, but when I use the same in AIX I am not getting any output.

the unix processes name look like this when I do ps -ef |grep co_java

co_java_xxx co_java_yyyy co_java_mmmmm etc...

The script goes like this

ps -ef | /u/gnu/bin/perl -ne 'print $2 if /.*(\bco_java_)(\w+\n)/'

The output of this perl script should gives me the process name like below in HPUX

xxx yyyy mmmmm etc...

And in AIX no output comes out. Is there any code which I can use in HPUX and AIX to display this information?

Any help is really appreciated

dbadmin

20051020 Janitored by Corion: Added formatting

Replies are listed 'Best First'.
Re: Process display
by northwind (Hermit) on Oct 20, 2005 at 18:52 UTC

    Your problem centers on ps having different flags on different systems.  Check out ppk for some inspiration (don't look too hard though, the code is from when I was beginning in Perl).  I know the code does not do what you are wanting, but it does deal with ps having differnt flags on different systems.

Re: Process display
by ikegami (Patriarch) on Oct 20, 2005 at 19:30 UTC

    By the way,
    print $2 if /.*(\bco_java_)(\w+\n)/
    is less efficient and less readable than
    print $1 if /\bco_java_(\w+\n)/

      Hi, Thanks for the quick response everyone. The ps -ef output is like below juserl 8593596 1 0 Oct 15 - 0:43 co_java_for03 - AIX juserl 23107 1 0 Oct 15 ? 1:15 co_java_burl9 - HPUX I think both these outputs looks same, but how perl interprets it I am not sure. Thanks, dbadmin
        if that's true, the code you presented would work. Is the path to Perl correct? Are there trailing spaces in the output?
Re: Process display
by amw1 (Friar) on Oct 20, 2005 at 18:48 UTC
    Is the output of ps -ef identical on both HPUX and AIX? I suspect the issue lies there.
Re: Process display
by blazar (Canon) on Oct 21, 2005 at 10:42 UTC
    Since nobody has mentioned it yet, and you're processing the output of ps(1), you may be interested in (knowing about and possibly) using Proc::ProcessTable.