Thanks, it's working now.  I couldn't get the perl kill to work, it kept
dieing.  I used system("kill $mypid") and it kills everything :-).

Thanks again

-----Original Message-----
From: Paul Johnson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 10, 2002 10:18 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Problem with variable in system command



> Thanks for your replies.  I understand that system() returns an exit
> code when it is done.  My problem is that the command to be run by
> system() is not getting the variable.
>
> Here is the error I get when I run the script...
>
> 98299
> usage: kill [-s signal_name] pid ...
>       kill -l [exit_status]
>       kill -signal_name pid ...
>       kill -signal_number pid ...
>
>
> 98299 is what is found in the pid file.  Why is this number not being
> passed to the kill command in system ("kill $mypid").  I have used
> something similar to this in other scripts with no problems.

The something similar is probably:

     $mypid = `cat $afile`;
     chomp($mypid);

It's not working currently because the cat command prints 98299 to the
screen, and $mypid gets the return value from system.
But really, you don't want to be using cat at all.  Open the file yourself
and read the value.
    open F, $afile or die "Can't open $afile: $!";
    my $mypid = <F>;
    chomp $mypid;
    close F or die "Can't close $afile: $!";

You want to be using Perl's kill function too:

    kill $sig, $mypid or die "Can't signal $mypid";

where $sig is whatever signal you want to send.

perldoc -f kill

>
> -----Original Message-----
> From: Dharmender Rai [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, October 10, 2002 8:40 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED];
> [EMAIL PROTECTED]
> Subject: RE: Problem with variable in system command
>
>
> Anthony,
>  system() return the exit status. Type "perldoc -f
> system" . When the command is successful, you will get
> 0.
> --- [EMAIL PROTECTED] wrote: > As a
> test I would print $mypid and it had the
>> correct pid number in it.
>>
>> Here is the complete script, if it will help...
>>
>> #!/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: Dharmender Rai
>> [mailto:[EMAIL PROTECTED]]
>> Sent: Thursday, October 10, 2002 8:06 AM
>> To: [EMAIL PROTECTED];
>> [EMAIL PROTECTED]
>> Subject: Re: Problem with variable in system command
>>
>>
>>
>> $mypid contains the status of the process not its
>> pid.
>>  --- [EMAIL PROTECTED] wrote: > 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]
>> >
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Everything you'll ever need on one web page
>> from News and Sport to Email and Music Charts
>> http://uk.my.yahoo.com
>>
>> --
>> To unsubscribe, e-mail:
>> [EMAIL PROTECTED]
>> For additional commands, e-mail:
>> [EMAIL PROTECTED]
>>
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net



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

Reply via email to