Hi and Help,

I have a perl script (A) that spawns a unix command and pipes that to a log file. Then 
at 23:59 I have a perl script (B) that kills script (A). At midnight script (A) is 
kicked off. 

My issue is my killing of srcipt (A) is not working. It either is showing under ps, 
but not doing anything or its still writing to the old log file, along with the new 
file. 

Are my perl scripts not correct? Is there an easier way to do this? Thanks up 
front......

Rob


Script (A):
#!/bin/perl -w
use warnings;
use strict;
 
my ( $sec, $min, $hour, $day, $mon, $year ) = localtime;
my $snoop   = '/usr/sbin/snoop -d ge0 -ta';
my $date = `date +%W`;
chop($date);
my $dir = "/var/weeks/03_week_$date";
my $logfile = sprintf '/var/weeks/03_week_%d/%02d%02d%02d%02d%02d.sno',
    `date +%W`, $year % 100, $mon + 1, $day, $hour, $min;
 
# create 03_week_dir if does not exist
unless(-d $dir){
mkdir $dir,0660;
} 
 
open LOG, '>', $logfile or die "Cannot open $logfile: $!";
# set default output filehandle and autoflush
select LOG;
$| = 1;
 
print '===============' . localtime() . " ==================\n\n";
 
open SNOOP, "$snoop |" or die "Cannot open pipe from $snoop: $!";
 
while ( <SNOOP> ) {
    print;
    }

#
#

Script(B):
#!/bin/perl 
 
@snp = `pgrep snp.pl`;
pop(@snp);
@snoop = `pgrep snoop`;
push(@snp,@snoop);
chomp(@snp);
 
foreach (@snp) {
#print("Killing $_\n");
`kill -9 $_`;
}


Cron:
#59 23 * * *  /bin/pkill -9 snp.pl;/bin/pkill -9 snoop;/bin/pkill -9 snoop;/bin/pkill 
-9 snp.pl  # test
59 23 * * *  /opt/script/killsnp.pl > /dev/null 2>&1 # to kill
0 0 * * *  /opt/script/snp.pl & > /dev/null 2>&1 # to start


This mornings ps -ef|
  nobody  5833  5823  2 00:00:00 ?       45:26 /usr/sbin/snoop -d ge0 -ta
  root  5823     1  0 00:00:00 ?        0:07 /bin/perl -w /opt/script/snp.pl
  nobody  1928  1925  1 13:27:00 ?       58:07 /usr/sbin/snoop -d ge0 -ta
  root  1925     1  0 13:27:00 ?        0:34 /bin/perl -w /opt/script/snp.pl





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

Reply via email to