Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  •     # The sed bit is embarrassing but needed on a Cat restart
        # when the shell quotes things :/
        chomp(my @processes
          = uniq `ps -ef|grep "$user.*$app_name"|grep -v grep|sed -e 's/"//g' -e 's/.* script//'`
        );

    Why use Sed at all? Won't it work to do the transformations on Perl list elements rather than on lines in the shell?

      chomp my @processes = uniq map { tr/"//d; s/.* script//; $_ }
        `ps -ef|grep "$user.*$app_name"|grep -v`;
    • Why use the shell at all? Shame on you both with your platform specific solutions.

      See Proc::ProcessTable [cpan.org]

      • I wholeheartedly use and recommend Proc::ProcessTable. That is until I had to use it [kevinspencer.org] on an Opteron Solaris 10 box. I was in a hurry so I just said bugger it and scraped the output of ps instead.
        • There's a bug in Proc::ProcessTable, though I couldn't tell you what it is offhand. The sys-proctable [rubyforge.org] library, which started as a port of Dan's work, picks up other processes just fine.

          The only security change for /proc they made between 9 and 10 that I'm aware of is the cmdline information is now restricted to 80 characters unless you own the process. Which, in practice, meant we had to shell out to use /usr/ucb/ps -auxwww so we could distinguish between the Java processes with ridiculously long command