Config::Crontab's POD does have a long example for how to read/write users crontabs in it...
$c = new Config::Crontab;
$c->owner('joe');
$c->read; ## reading joe's crontab
$c->write; ##write out to joe's crontab...
$c->owner('bob'); #change user to bob
$c->write; #write same crontab to bob's crontab
Update:
It does look as though Config::Crontab handles restarting crontab and setting other user's crontabs via the system crontab command -- but looking though the code a few things you need to be aware of:
1: As you can see below the crontab command is not absolute -- you should make sure your PATH is set correctly before calling this write function -- or better yet modify Config::Crontab to use a setting to define where crontab exists on the filesystem (and maybe submit a patch).
my $crontab;
if( my $owner = $self->owner ) {
$crontab = `crontab -u $owner $tmpfile 2>&1`;
}
else {
$crontab = `crontab $tmpfile 2>&1`;
}
chomp $crontab;
unlink $tmpfile;
if( $crontab || $? ) {
$self->error($crontab);
if( $self->strict ) {
carp "Error writing crontab (crontab exited with status " .
($? >> 8) . "): " . $self->error;
}
return;
}
}
return 1;
}
2: The Module does not check if you are root before trying to update any users crontab -- if you are modding users crontabs other than your running UID, you should run as root and also verify the script is running as root before you call the writes.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.