Rmck wrote:
> 
> Hi

Hello,

> I'm trying to get this to work in perl.

Which version of Perl?

> I want to start a unix process send it to a log file. Then at midnight
> kill it and restart it, with the date at the top.

Why do you need to kill and restart it?  Can't you just print the date at
midnight and keep it running?

> I'm starting with the following but the intial start of the proccess
> is not working right:
> 
> #!/bin/perl
> $date = `date | awk '{print $4}'`;

Perl has localtime() and gmtime() built-in so you don't have to run an
external program to get the time and if you need special formating you
can use sprintf() or POSIX::strftime().

> $snoop = "/usr/sbin/snoop";
> $filename = "`date +%y%m%d%H%M`.sno";

You can use POSIX::strftime() to do that without running an external program.

> $logfile = "/opt/$filename";
> $pid = `/bin/pgrep snp.pl`;
> 
> system("/usr/sbin/snoop -d ge0 -ta >> $logfile &");
> 
> until ("1" eq "0"){

This is usually written as:

while ( 1 ) {

Or:

for ( ;; ) {


> if ($date == "00:00:00"){

You don't change the value of $date in the loop so this will never be true.


> system("/bin/pkill -P $pid");
> print "=========== `date` ==================\n" > $logfile;
> system("/usr/sbin/snoop -d ge0 -ta >> $logfile &");
> }
>   }
> 
> Any suggestions would be helpfull.

Here are some UNTESTED suggestions:

#!/bin/perl
use warnings;
use strict;

my ( $sec, $min, $hour, $day, $mon, $year ) = localtime;

my $snoop   = '/usr/sbin/snoop -d ge0 -ta';
my $logfile = sprintf '/opt/%02d%02d%02d%02d%02d.sno',
    $year % 100, $mon + 1, $day, $hour, $min;

open LOG, '>', $logfile or die "Cannot open $logfile: $!";
# set default output filehandle and autoflush
select LOG;
$| = 1;

print '=========== ' . localtime . " ==================\n";

open SNOOP, "$snoop |" or die "Cannot open pipe from $snoop: $!";

while ( <SNOOP> ) {
    print;
    # restart this process if midnight
    ( $sec, $min, $hour ) = localtime;
    exec $0 if $sec + $min + $hour == 0;
    }

__END__



John
-- 
use Perl;
program
fulfillment

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

Reply via email to