19 Aug 2010 16:40:40 UTC
- Distribution: App-Cronjob
- Source (raw)
- Browse (raw)
- How to Contribute
- Clone git repository
- Issues (0)
- Testers (165 / 0 / 0)
- KwaliteeBus factor: 1
- License: perl_5
- Download (13.7KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:
cronjob - wrap up programs to be run as cron jobs
cronjob [-cEfjrs] [long options...] -c --command command to run (passed to ``) -s --subject subject of mail to send (defaults to command) -r --rcpt recipient of mail; may be given many times -E --errors-only do not send mail if exit code 0, even with output -f --sender sender for message -j --jobname job name; used for locking, if given --ignore-errors error types to ignore (like: lock) --lock lock this job (defaults to true; --no-lock for off)
cronjob is a fairly simple Perl program that's meant to be used to wrap anything you want run from a crontab. It was originally written to cope with the highly deficient Solaris crond, but now provides features that are useful even under relatively sane and otherwise tolerable cron daemons.
The most important argument to cronjob is
-c). It gives the command to be run. If you want to run some-maintenance-job every day at noon, you might put this in your crontab:
0 12 * * * cronjob -c 'some-maintenance-job --xyzzy'
Here's what will happen when that job is run:
Unless you provided
--no-lock, an exclusive lock will be created on a temporary file in /tmp. The locking process is described more below. Basically, it tries to prevent more than one of the same, or closely-related, jobs from running concurrently.
The job will be run with no input. Its combined STDOUT and STDERR are captured, along with its exit (wait) status.
When the command has terminated, a report is sent if:
the command couldn't lock (unless
the command had any output (unless
the command exited non-zero (always)
The report will include a summary of the process and its behavior, including the time taken to run, the exit status, any signal received, and whether core was dumped. It will also include the full (combined) output of the process.
The report will be send from
--sender(or a reasonable default) to
In-Reply-Toheader will be set to a hashed value that will cause all same-subject jobs to thread together in threaded mail readers. The
--subjectswitch sets the message subject, so it's responsible for deciding which jobs thread together. For jobs that run with variable arguments, providing a
--subjectargument is a very good idea.
The default lockfile name is generated with code something like this:
my $lockname = $opt->jobname || ( md5_sum( $opt->subject || $opt->command ) ); my $lockfile = sprintf '/tmp/cronjob.%s', $lockname;
In other words, if you specify a
--jobnameoption, that will be used for naming the lockfile. This lets you force otherwise unrelated cronjobs to block each other. If you don't provide a job name, one is created by hashing the subject (of the report to send) or, failing that, the command itself. The hashing is a simple measure to prevent long or metacharacter-ridden filenames.
The lockfile will contain information about the process that has the lock, including when it was begun.
By default, all jobs are locked and failure to acquire a lock causes immediate failure of the cronjob. A failure report will be sent. To suppress failure reports in the event of lock failure, pass
--ignore-errors lockto the command. To skip locking, pass
Ricardo Signes <firstname.lastname@example.org>
This software is copyright (c) 2009 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|