Anthony Kernan wrote: > > 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;
This is a useless test because the file system wouldn't return the name of a file if it didn't exist. > push @dirstruct, $entry if (($entry ne '') AFAIK a file system entry can not have zero length. > && (( m/$ext$/) Your regular expression doesn't work the way you intended because the variable $ext contains the . meta-character. > and (substr $entry, 0, -4))); #This will only work with *.pid > } Try this instead: #!/usr/bin/perl -w use strict; use File::Find; my $dir = '/usr/local/etc/mrtg'; my $ext = qr/\.pid$/; my @dirstruct; find( \&wanted, $dir ); foreach my $afile ( @dirstruct ) { chomp( my $mypid = qx/head -1 $afile/ ); print "Killing instance...$mypid\n"; kill 'TERM', $mypid; # use 'KILL' to force it } exit 0; sub wanted { return unless /$ext/; push @dirstruct, $File::Find::name if length substr $_, 0, -4; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]