ticks and FreeBSD

Discussion in 'Perl Misc' started by Erik Tank, Dec 15, 2003.

  1. Erik Tank

    Erik Tank Guest

    I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything is
    working well with the exception of the following:
    my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;


    The baisc idea is that I want to see if a program called jmaild is
    running. On RedHat 9 it @jmail_return_lines would contain the ps -aux
    lines but under FreeBSD it returns nothing even though when I take the
    command in the ticks and run it from the command line it does return a
    line.

    Any help or suggestions would be greatly appreciated.

    Erik
     
    Erik Tank, Dec 15, 2003
    #1
    1. Advertising

  2. On Mon, 15 Dec 2003 17:38:49 GMT
    Erik Tank <> wrote:

    > I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything
    > is working well with the exception of the following:
    > my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;
    >
    >
    > The baisc idea is that I want to see if a program called jmaild is
    > running. On RedHat 9 it @jmail_return_lines would contain the ps
    > -aux lines but under FreeBSD it returns nothing even though when I
    > take the command in the ticks and run it from the command line it
    > does return a line.
    >
    > Any help or suggestions would be greatly appreciated.


    You could look into using a module..

    Take a look at Proc::Table.

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    The light at the end of the tunnel is the headlight of an
    approaching train.
     
    James Willmore, Dec 16, 2003
    #2
    1. Advertising

  3. Erik Tank

    ko Guest

    Erik Tank wrote:

    > I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything is
    > working well with the exception of the following:
    > my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;
    >
    >
    > The baisc idea is that I want to see if a program called jmaild is
    > running. On RedHat 9 it @jmail_return_lines would contain the ps -aux
    > lines but under FreeBSD it returns nothing even though when I take the
    > command in the ticks and run it from the command line it does return a
    > line.
    >
    > Any help or suggestions would be greatly appreciated.
    >
    > Erik


    Works for me, Perl 5.005_03 and 5.8.2 (changed shebang line for 5.8.2).
    FreeBSD 4.9 - but that shouldn't matter since the options to grep and ps
    are the same:

    $ cat ticks && ./ticks
    #!/usr/bin/perl -w
    use strict;

    my @sh = `ps -ax | grep '/bin/sh' | grep -v grep`;
    print $sh[0];

    452 p1 S 0:00.01 /bin/sh

    Have you tried looking for problems elsewhere in the script? Do you have:

    use strict;
    use warnings;

    enabled at the top of the script? If not, that would be a good start.

    HTH - keith
     
    ko, Dec 16, 2003
    #3
  4. Erik Tank

    Mike Hunter Guest

    On Mon, 15 Dec 2003 17:38:49 GMT, Erik Tank wrote:

    > I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything is
    > working well with the exception of the following:
    > my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;


    Freebsd likes ps -ef better.

    Mike
     
    Mike Hunter, Dec 16, 2003
    #4
  5. Michele Dondi <> wrote:

    > chomp(my @jmail_return_lines = grep /jmaild/, qx{ps -aux});
    > ^^^^^ ^^^ ^
    > (1) (2)


    > (2) it's just me,



    No it isn't. :)


    > but for some reason



    Mine is:

    There's about 2 pixels difference between "slants" of
    single quotes and it makes me squint (ie. slows down
    my reading of the code).


    > I can't stand the backticks
    > chars :)



    Me either.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 17, 2003
    #5
  6. Erik Tank

    Erik Tank Guest

    Although this is getting out of the scope fo this group but -ef only
    shows processes associated with your user where as -aux shows them
    all.

    On Tue, 16 Dec 2003 19:34:14 +0000 (UTC), Mike Hunter
    <> wrote:

    >On Mon, 15 Dec 2003 17:38:49 GMT, Erik Tank wrote:
    >
    >> I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything is
    >> working well with the exception of the following:
    >> my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;

    >
    >Freebsd likes ps -ef better.
    >
    >Mike
     
    Erik Tank, Dec 17, 2003
    #6
  7. On Mon, 15 Dec 2003 17:38:49 GMT, Erik Tank <> wrote:

    >I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything is
    >working well with the exception of the following:
    > my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;


    Not an answer to your question, but since nobody has complained yet, I
    feel like pointing out that while the above approach is perfectly
    "legal", indeed it looks rather awkward too. Why not let Perl use its
    own tools to extract the lines you need?

    See this (untested) for example:

    chomp(my @jmail_return_lines = grep /jmaild/, qx{ps -aux});
    ^^^^^ ^^^ ^
    (1) (2)

    (1) bonus chomp(), because you may want it anyway: if not so, then
    throw it away,

    (2) it's just me, but for some reason I can't stand the backticks
    chars :)


    Michele
    --
    # This prints: Just another Perl hacker,
    seek DATA,15,0 and print q... <DATA>;
    __END__
     
    Michele Dondi, Dec 18, 2003
    #7
  8. On Wed, 17 Dec 2003 07:51:23 -0600, (Tad
    McClellan) wrote:

    [about reasons for disliking backticks]
    >Mine is:
    >
    > There's about 2 pixels difference between "slants" of
    > single quotes and it makes me squint (ie. slows down
    > my reading of the code).


    Actually I'm not sure myself, but I'd say I do not like them for

    (i) they were/are not available on *my* italian keyboard (there are
    two possible layouts),

    (ii) I learned to use $(...) in (ba)sh instead, that has as an added
    value the possibility of nesting,

    (iii) probably I'm concerned with their aesthetic appeal: those *two*
    "thingies" pointing to the left! In fact I'm not bothered using that
    char in TeX's `...' or ``...'', and in that context lots ALT-96's are
    not a problem. But then a smart text editor is much better anyway!!


    Michele
    --
    # This prints: Just another Perl hacker,
    seek DATA,15,0 and print q... <DATA>;
    __END__
     
    Michele Dondi, Dec 18, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TC
    Replies:
    1
    Views:
    1,431
    Eliyahu Goldin
    Apr 21, 2005
  2. Caleb Hattingh
    Replies:
    2
    Views:
    23,178
    Caleb Hattingh
    Mar 31, 2006
  3. Tim_Mac
    Replies:
    3
    Views:
    1,931
    Tim_Mac
    Sep 12, 2006
  4. Lord0
    Replies:
    0
    Views:
    1,038
    Lord0
    Oct 25, 2006
  5. chandanlinster
    Replies:
    6
    Views:
    511
    Joe Estock
    Apr 25, 2007
Loading...

Share This Page