Debian Codegraph @

README

raw
1 Config/Crontab
2 ==============
3
4 Config::Crontab reads and writes (and pretty-prints) your crontab(5)
5 files. It is compatible with Vixie-style crontabs (and all subsets,
6 including Solaris' SysV-style crontabs).
7
8 Config::Crontab has a simple, object-oriented syntax. Crontab files
9 are broken into "blocks" (paragraphs, each separated by two or more
10 newlines); the Block is the basic unit of a Config::Crontab object.
11
12 You can re-order entire blocks within a crontab file, re-order lines
13 within blocks (there are three types of lines: comments, environment
14 settings, and crontab commands or events), remove blocks or lines
15 within blocks, add new blocks or lines within blocks, etc. See the
16 Config::Crontab manpage for full details.
17
18 Config::Crontab will do basic regular expression syntax checks; it
19 won't allow obvious garbage (e.g., 'F * * * * /bin/bar' would fail
20 since 'F' is not valid), but it won't check for nonsensical entries
21 such as '10-2 * * * * /bin/bar' (the minute range specified is
22 invalid). However, if you attempt to commit an invalid crontab, the
23 'write' method will return undef and the 'error' method will be set
24 (with the output of crontab(1)) if the crontab is rejected by the
25 crontab program.
26
27 EXAMPLES
28
29 Example 1:
30 ==========
31
32 Consider this example of parsing a crontab, re-schedule a cron event,
33 and commit the changes. Given:
34
35 30 5 * * 1-5 /bin/foo
36
37 we want to re-schedule the event to run at 4:30a instead. Here is one
38 way, creating an B<Event> object:
39
40 my $ct = new Config::Crontab; $ct->read;
41 my ($event) = $ct->select(-command_re => '/bin/foo');
42 $event->hour(4);
43 $ct->write;
44
45 and here is a shortcut to do the same thing:
46
47 my $ct = new Config::Crontab; $ct->read;
48 ($ct->select(-command_re => '/bin/foo'))->hour(4);
49 $ct->write;
50
51 Example 2:
52 ==========
53
54 The following example is equivalent to 'crontab -l':
55
56 $ct = new Config::Crontab; $ct->read; print $ct->dump;
57
58 Example 3:
59 ==========
60
61 The following example is equivalent to 'crontab -u joe -l':
62
63 $ct = new Config::Crontab( -owner => 'joe' );
64 $ct->read;
65 print $ct->dump;
66
67 You can even copy crontabs from one user to another:
68
69 ## must be run as root or other privileged user
70 $ct = new Config::Crontab( -owner => 'joe' );
71 $ct->read;
72 $ct->owner('sherman');
73 $ct->write;
74
75 Example 4:
76 ==========
77
78 You may also make a backup of your crontab:
79
80 $ct = new Config::Crontab; $ct->read;
81 $ct->file('mycrontab.bak'); $ct->write;
82
83 You can also disable an entire block of commands. Consider the
84 following crontab file:
85
86 # refresh apache duds
87 1 0 * * * kill -1 `ps -x | egrep 'Master:.+? \(https?d\)' | awk '{print $1}'`
88
89 # in-house stats files
90 0 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c online.config -v
91 2 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c police.config -v
92 4 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c scott.config -v
93 6 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c tubbing.config -v
94 8 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c perlcode.config -v
95 10 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c fritzen.config -v
96 12 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c josh.config -v
97 14 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c rhett.config -v
98
99 # do log files
100 0 3 * * * $HOME/usr/bin/movelogs.pl -v -k -a
101
102 we want to turn off all the stats processing. So we do this:
103
104 $ct = new Config::Crontab; $ct->read;
105 $ct->block($ct->select(-command_re => 'mkstats'))->active(0);
106 $ct->write;
107
108 and here's another way:
109
110 $ct = new Config::Crontab; $ct->read;
111 $_->active(0) for $ct->select(-command_re => 'mkstats');
112 $ct->write;
113
114 Notice all the mkstats lines are commented out:
115
116 # refresh apache duds
117 1 0 * * * kill -1 `ps -x | egrep 'Master:.+? \(https?d\)' | awk '{print $1}'`
118
119 # in-house stats files
120 #0 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c online.config -v
121 #2 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c police.config -v
122 #4 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c scott.config -v
123 #6 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c tubbing.config -v
124 #8 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c perlcode.config -v
125 #10 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c fritzen.config -v
126 #12 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c josh.config -v
127 #14 1 * * * $HOME/usr/bin/mkstats2.3/mkstats.pl -c rhett.config -v
128
129 # do log files
130 0 3 * * * $HOME/usr/bin/movelogs.pl -v -k -a
131
132 Re-activating these lines is a matter of setting active to 'true':
133
134 $ct = new Config::Crontab; $ct->read;
135 $ct->block($ct->select(-command_re => 'mkstats'))->active(1);
136 $ct->write;
137
138 INSTALLATION
139
140 To install this module type the following:
141
142 perl Makefile.PL
143 make
144 make test
145 make install
146
147 DEPENDENCIES
148
149 This module requires these other modules and libraries:
150
151 none
152
153 COPYRIGHT AND LICENCE
154
155 This library is free software; you can redistribute it and/or modify
156 it under the terms of the Perl Artistic License.
157
158 Copyright (C) 2003-2005 Scott Wiersdorf. All Rights Reserved.