App::RunCron - making wrapper script for crontab
use App::RunCron; my $runner = App::RunCron->new( timestamp => 1, command => [@ARGV], logfile => 'tmp/log%Y-%m-%d.log', reporter => 'Stdout', error_reporter => [ 'Stdout', 'File', { file => 'tmp/error%Y-%m-%d.log' }, ], ); $runner->run;
App::RunCron is a software for making wrapper script for running cron tasks.
App::RunCron can separate reporting way if the command execution success or failed (i.e. fails to start, or returns a non-zero exit code, or killed by a signal). It is handled by `reporter` and `error_reporter` option.
By default, `reporter` is 'None' and `error_reporter` is 'Stdout'. It prints the outputs the command if and only if the command execution failed. In other words, this behaviour causes cron(8) to send mail when and only when an error occurs.
Default behaviour is same like cronlog.
Add timestamp or not. (Default: undef)
Identifier of the job name. (Optional)
command to be executed. (Required)
If logfile is specified, stdout and stderr of the command will be logged to the file so that it could be used for later inspection. If not specified, the outputs will not be logged. The logfile can be a strftime format. eg. '%Y-%m-%d.log'. (NOTICE: '%' must be escaped in crontab.)
strftime
common_reporter is optional, processing after (error_)?reporter is handled.
common_reporter
(error_)?reporter
The reporter, error_reporter and common_reporter can be like following.
reporter
error_reporter
$module_name
[$module_name[, \%opt], ...]
$coderef
$module_name package name of the plugin. You can write it as two form like Plack::Middleware:
reporter => 'Stdout', # => loads App::RunCron::Reporter::Stdout
If you want to load a plugin in your own name space, use the '+' character before a package name, like following:
reporter => '+MyApp::Reporter::Foo', # => loads MyApp::Reporter::Foo
Package name of an "Announcer" which announce job information before running the job. (Optional)
$self->run
Running the job.
my $str = $self->result_line
One line result string of the command.
my $str = $self->report
Retrieve the output of the command.
my $bool = $self->is_success
command is success or not.
my $int = $self->exit_code
same as $?
$?
my $int = $self->child_exit_code
exit code of child process.
my $int = $self->child_signal
signal number if chile process accepted a signal.
runcron, cronlog
Copyright (C) Songmu.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Songmu <y.songmu@gmail.com>
To install App::RunCron, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::RunCron
CPAN shell
perl -MCPAN -e shell install App::RunCron
For more information on module installation, please visit the detailed CPAN module installation guide.