Steve,

Thanks for your response.

On Tue, 2003-03-25 at 12:31, Steve Grazzini wrote:
> Kevin Old <[EMAIL PROTECTED]> wrote:
> > 
> > Basically all I do is pipe the input from ps into my perl program, and
> > grep for cdlor.....but the path to perl has moved (long story) and the
> > cdlor isn't printed in the command output from ps.
> 
> Can you explain?  
> 
> I can't see why changing the path to perl would break the "ps|grep"
> command...

Ok, I had perl installed under /home/motorola/local/bin/perl.  Because
of other scripts running on this server that break when run under Perl
5.6.1, I installed that under /home/motorola/local/bin/perl5.6.1.  When
I get the "command" back from ps it doesn't show the entire command. 
For example I have a script running under cron....named cdlorcl.pl. 
Before the command from ps would show as:

/home/motorola/local/bin/perl cdlor

now it shows as 

/home/motorola/local/bin/perl5.6.1

Evidently there is a limit of the number of characters the cmd from ps
will show?

Any ideas?


> 
> > #!/usr/bin/perl -w
> > 
> > $regex =
> > '^\s{0,4}(\d{1,7})\s?(\d{2}:\d{2}:\d{2}|\s{0,3}\w{4}\d{2})\s{0,8}(\d{1,4}
> > -?)?(\d{2}):(\d{2}):(\d{2})';
> 
> I prefer unpack() for this sort of thing -->
> 
>     #
>     # this was for Solaris "top", but you get the idea
>     #
>     my @fields   = qw(pid psid user thr pri nice size res state time cpu cmd);
>     my @template = qw(A6  A6   A9   A4  A4  A4   A6   A6  A7    A7   A7  A*);
> 
>     my %ret;
>     while (<TOP>) {
>         next if 1..5;
> 
>         my %proc;
>         s/^\s+//, s/\s+$//
>             for @[EMAIL PROTECTED] = unpack "@template", $_;
> 
>         $ret{$proc{pid}} = \%proc;
>     }
>     wantarray ? %ret : \%ret;
>   }
> 
> > $pipe = open(PH, "ps -eo pid,stime,etime,comm \| grep cdlor |");
>                                                 ^
> No need to escape the pipe.
> 
> [ snip parsing ]
> 
> > foreach $p (@pids) {
> > 
> >         $count{$p}++;
> >         print $p . "\n";
> > 
> >         next if $count{$p} >= 2;
> > 
> >         @sysargs = ("kill", $p);
> >         system("kill $p") == 0 and print "$p killed\n";
> >         # or die "system @sysargs failed $?";
> 
> And here you could use the kill() function instead of system().  It's
> faster -- doesn't spawn a subprocess -- and lets you do a better job
> of error checking and reporting.
> 
> 
> > }
> > 
> 
> -- 
> Steve
-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to