chanakya has asked for the wisdom of the Perl Monks concerning the following question:
The above code works perfectly in the daemon mode and normal mode.#!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Proc::Daemon; use Log::Log4perl qw(get_logger :easy :levels); Use MysqlUtils; use vars qw($opt_daemon, $opt_mailid); GetOptions( "daemon|d" => \$opt_daemon, "mailid|a=s" => \$opt_mailid, "help|h" => \&usage, ) || usage(); if(!$opt_mailid){ $opt_mailid = shift || usage(); } chomp($opt_mailid); &usage if( (!defined($opt_mailid)) && (@ARGV==0) ); if(scalar(@ARGV) > 0){ if ( (!defined ($opt_mailid)) || (@ARGV > 0) ) { usage(); die("Invalid Argument passed"); } } if($opt_daemon) { ##Inits print STDOUT "Daemon mode \n"; Proc::Daemon::Init; Log::Log4perl->init_once("$ENV{CONF}" . "/log4perl.conf"); my @mail_ids = qw(200909101 200909102 200909103); while (1) { foreach my $opt_mailid (@mail_ids) { my ($log) = Log::Log4perl::get_logger('main'); my $data = get_data('mail_id' => $opt_mailid, 'file_path' => " +/spool/emails"); ##connect db MysqlUtils::connect(); eval { MysqlUtils::insert_record($data); }; if($@) { $log->error("unable to insert data"); } } } } else { print STDOUT "Normal mode\n"; my ($log) = Log::Log4perl::get_logger('main'); my $data = get_data('mail_id' => $opt_mailid, 'file_path' => "/spo +ol/emails"); ##connect db MysqlUtils::connect(); eval { MysqlUtils::insert_record($data); }; if($@) { $log->error("unable to insert data"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Executing script in normal/daemon mode and adding start/stop capability
by almut (Canon) on Oct 07, 2009 at 12:35 UTC | |
|
Re: Executing script in normal/daemon mode and adding start/stop capability
by ELISHEVA (Prior) on Oct 07, 2009 at 11:12 UTC | |
|
Re: Executing script in normal/daemon mode and adding start/stop capability
by afoken (Chancellor) on Oct 07, 2009 at 22:23 UTC | |
|
Re: Executing script in normal/daemon mode and adding start/stop capability
by chanakya (Friar) on Oct 08, 2009 at 06:47 UTC |