2007/12/28 22:16:00 test.pl 84> INFO: this is a test 2007/12/28 22:16:00 test.pl 84> 0: 2007/12/28 22:17:00 test.pl 84> 0: 2007/12/28 22:17:00 test.pl 84> INFO: this is a test 2007/12/28 22:17:00 test.pl 84> 0: 2007/12/28 22:18:00 test.pl 84> 0: 2007/12/28 22:18:00 test.pl 84> INFO: this is a test 2007/12/28 22:18:00 test.pl 84> 0: #### # tail /tmp/testfile Fri Dec 28 22:12:00 GMT 2007 ... Fri Dec 28 22:18:00 GMT 2007 Fri Dec 28 22:19:00 GMT 2007 Fri Dec 28 22:20:00 GMT 2007 Fri Dec 28 22:21:00 GMT 2007 #### #!/usr/bin/perl use Data::Dumper; use Carp; use Schedule::Cron; use Sys::Hostname; use Log::Log4perl qw(get_logger); ############################################### #Variable declarations my $rootdir = "/usr/local/appname"; my $script = "test"; ############################################### #MAIN #OpenLog ($logfile); my $cron = new Schedule::Cron(\&dispatcher, nofork => 1, log => \&Log, ); $cron->add_entry("* * * * *", {'subroutine' => \&TestSub, } ); $cron->run(detach=>1, pid_file=>"$rootdir/bin/$script.pid"); ###################################################### sub dispatcher { print "ID: ",shift,"\n"; print "Args: ","@_","\n"; } ###################################################### sub TestSub { Log ("INFO", "", "this is a test"); `date >> /tmp/testfile`; } ###################################################### sub Log { my ($level, $subject, $msg) = @_; my $conf = q( log4perl.category.appname = INFO, Logfile log4perl.appender.Logfile = Log::Log4perl::Appender::File log4perl.appender.Logfile.filename = /usr/local/appname/logs/appname.pl.log log4perl.appender.Logfile.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = %d %F{1} %L> %m %n ); Log::Log4perl::init(\$conf); my $logger = get_logger("appname"); $logger->info("$level: $msg"); if ($level eq "ERR") { $logger->error($msg); } }