Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / cron.aug
1 (*
2 Module: Cron
3  Parses /etc/cron.d/*, /etc/crontab
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: Reference
8  This lens tries to keep as close as possible to `man 5 crontab` where
9  possible.
10
11 About: License
12   This file is licensed under the LGPL v2+, like the rest of Augeas.
13
14 About: Lens Usage
15   Sample usage of this lens in augtool
16
17     * Get the entry that launches '/usr/bin/ls'
18       >  match '/files/etc/crontab/entry[. = "/usr/bin/ls"]'
19
20 About: Configuration files
21   This lens applies to /etc/cron.d/* and /etc/crontab. See <filter>.
22 *)
23
24 module Cron =
25   autoload xfm
26
27 (************************************************************************
28  * Group:                 USEFUL PRIMITIVES
29  *************************************************************************)
30
31 (* Group: Generic primitives *)
32
33 (* Variable: eol *)
34 let eol     = Util.eol
35
36 (* Variable: indent *)
37 let indent  = Util.indent
38
39 (* Variable: comment *)
40 let comment = Util.comment
41
42 (* Variable: empty *)
43 let empty   = Util.empty
44
45 (* Variable: num *)
46 let num        = /[0-9*][0-9\/,*-]*/
47
48 (* Variable: alpha *)
49 let alpha      = /[A-Za-z]{3}/
50
51 (* Variable: alphanum *)
52 let alphanum   = (num|alpha) . ("-" . (num|alpha))?
53
54 (* Variable: entry_prefix *)
55 let entry_prefix = /-/
56
57 (* Group: Separators *)
58
59 (* Variable: sep_spc *)
60 let sep_spc = Util.del_ws_spc
61
62 (* Variable: sep_eq *)
63 let sep_eq  = Util.del_str "="
64
65
66
67 (************************************************************************
68  * Group:                       ENTRIES
69  *************************************************************************)
70
71
72 (************************************************************************
73  * View: shellvar
74  *   A shell variable in crontab
75  *************************************************************************)
76
77 let shellvar =
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 ]
81
82 (* View: - prefix of an entry *)
83 let prefix     = [ label "prefix"       . store entry_prefix ]
84
85 (* View: minute *)
86 let minute     = [ label "minute"       . store num ]
87
88 (* View: hour *)
89 let hour       = [ label "hour"         . store num ]
90
91 (* View: dayofmonth *)
92 let dayofmonth = [ label "dayofmonth" . store num ]
93
94 (* View: month *)
95 let month      = [ label "month"        . store alphanum ]
96
97 (* View: dayofweek *)
98 let dayofweek  = [ label "dayofweek"  . store alphanum ]
99
100
101 (* View: user *)
102 let user       = [ label "user"         . store Rx.word ]
103
104
105 (************************************************************************
106  * View: time
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 ]
112
113 (* Variable: the valid values for schedules *)
114 let schedule_re = "reboot" | "yearly" | "annually" | "monthly"
115                 | "weekly" | "daily"  | "midnight" | "hourly"
116
117 (************************************************************************
118  * View: schedule
119  *   Time in the format "@keyword"
120  *************************************************************************)
121 let schedule    = [ label "schedule" . Util.del_str "@"
122                    . store schedule_re ]
123
124
125 (************************************************************************
126  * View: entry
127  *   A crontab entry
128  *************************************************************************)
129
130 let entry       = [ label "entry" . indent
131                    . prefix?
132                    . ( time | schedule )
133                    . sep_spc . user
134                    . sep_spc . store Rx.space_in . eol ]
135
136
137 (*
138  * View: lns
139  *   The cron lens
140  *)
141 let lns = ( empty | comment | shellvar | entry )*
142
143
144 (* Variable: filter *)
145 let 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" .
153   Util.stdexcl
154
155 let xfm = transform lns filter