3 Parses /etc/cron.d/*, /etc/crontab
5 Author: Raphael Pinson <raphink@gmail.com>
8 This lens tries to keep as close as possible to `man 5 crontab` where
12 This file is licensed under the LGPL v2+, like the rest of Augeas.
15 Sample usage of this lens in augtool
17 * Get the entry that launches '/usr/bin/ls'
18 > match '/files/etc/crontab/entry[. = "/usr/bin/ls"]'
20 About: Configuration files
21 This lens applies to /etc/cron.d/* and /etc/crontab. See <filter>.
27 (************************************************************************
28 * Group: USEFUL PRIMITIVES
29 *************************************************************************)
31 (* Group: Generic primitives *)
36 (* Variable: indent *)
37 let indent = Util.indent
39 (* Variable: comment *)
40 let comment = Util.comment
43 let empty = Util.empty
46 let num = /[0-9*][0-9\/,*-]*/
49 let alpha = /[A-Za-z]{3}/
51 (* Variable: alphanum *)
52 let alphanum = (num|alpha) . ("-" . (num|alpha))?
54 (* Variable: entry_prefix *)
55 let entry_prefix = /-/
57 (* Group: Separators *)
59 (* Variable: sep_spc *)
60 let sep_spc = Util.del_ws_spc
62 (* Variable: sep_eq *)
63 let sep_eq = Util.del_str "="
67 (************************************************************************
69 *************************************************************************)
72 (************************************************************************
74 * A shell variable in crontab
75 *************************************************************************)
78 let key_re = /[A-Za-z1-9_-]+(\[[0-9]+\])?/ - "entry" in
79 let sto_to_eol = store /[^\n]*[^ \t\n]/ in
80 [ key key_re . sep_eq . sto_to_eol . eol ]
82 (* View: - prefix of an entry *)
83 let prefix = [ label "prefix" . store entry_prefix ]
86 let minute = [ label "minute" . store num ]
89 let hour = [ label "hour" . store num ]
91 (* View: dayofmonth *)
92 let dayofmonth = [ label "dayofmonth" . store num ]
95 let month = [ label "month" . store alphanum ]
98 let dayofweek = [ label "dayofweek" . store alphanum ]
102 let user = [ label "user" . store Rx.word ]
105 (************************************************************************
107 * Time in the format "minute hour dayofmonth month dayofweek"
108 *************************************************************************)
109 let time = [ label "time" .
110 minute . sep_spc . hour . sep_spc . dayofmonth
111 . sep_spc . month . sep_spc . dayofweek ]
113 (* Variable: the valid values for schedules *)
114 let schedule_re = "reboot" | "yearly" | "annually" | "monthly"
115 | "weekly" | "daily" | "midnight" | "hourly"
117 (************************************************************************
119 * Time in the format "@keyword"
120 *************************************************************************)
121 let schedule = [ label "schedule" . Util.del_str "@"
122 . store schedule_re ]
125 (************************************************************************
128 *************************************************************************)
130 let entry = [ label "entry" . indent
132 . ( time | schedule )
134 . sep_spc . store Rx.space_in . eol ]
141 let lns = ( empty | comment | shellvar | entry )*
144 (* Variable: filter *)
146 incl "/etc/cron.d/*" .
147 incl "/etc/crontab" .
148 incl "/etc/crontabs/*" .
149 excl "/etc/cron.d/at.allow" .
150 excl "/etc/cron.d/at.deny" .
151 excl "/etc/cron.d/cron.allow" .
152 excl "/etc/cron.d/cron.deny" .
155 let xfm = transform lns filter