Here is the complete script...

#!/usr/bin/perl -w
use strict;
use File::Find;
my $dir = '/usr/local/etc/mrtg';
my $ext = '.pid';
my (@dirstruct);
my $mypid;

find(\&wanted,$dir);

foreach my $afile (@dirstruct) {
    $mypid = system("cat $afile");
    chop($mypid);
    print "Killing instance...";
    #print "$mypid";
    print $mypid;
    #system("kill $mypid");
    }
exit;

sub wanted {
  my $entry = "$File::Find::name" if -e;
  push @dirstruct, $entry if (($entry ne '') && (( m/$ext$/) and (substr
$entry, 0, -4))); #This will only work with *.pid
 }



>  -----Original Message-----
> From:         Kernan, Anthony  (GOT)  
> Sent: Thursday, October 10, 2002 7:40 AM
> To:   '[EMAIL PROTECTED]'
> Subject:      Problem with variable in system command
> 
> I've written a script to search for all *.pid files in a dir, then do
> a cat on the file.  The script will then use this variable to kill the
> process.  The problem I'm having is that the varibale is not being
> read correctly.  I run the script and the kill process tries to run
> without the variable.  Here is a post of the code I have.  Anyhelp
> would be greatly appreciated.
> 
> 
> find(\&wanted,$dir);
> 
> foreach my $afile (@dirstruct) {
>     $mypid = system("cat $afile");
>     chop($mypid);
>     print "Killing instance...";
>     system("kill $mypid");
> 
> 
> I wrote this script a few weeks ago and it worked great, but I
> accidentally deleted it and can't rememeber exactly how it was written.
> :-/
> 

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

Reply via email to