Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=f611b12cb74496422b787e002b922334f982c882 Commit: f611b12cb74496422b787e002b922334f982c882 Parent: 633926e58dd91c4c1ccd7b6450c0e2183ed093a8 Author: Raphael Pinson <[email protected]> AuthorDate: Wed Apr 8 12:23:54 2009 -0700 Committer: David Lutterkort <[email protected]> CommitterDate: Wed Apr 8 12:26:34 2009 -0700
Cron: new lens and test Parses /etc/crontab and /etc/cron.d --- lenses/cron.aug | 145 ++++++++++++++++++++++++++++++++++++++++++++ lenses/tests/test_cron.aug | 39 ++++++++++++ 2 files changed, 184 insertions(+), 0 deletions(-) diff --git a/lenses/cron.aug b/lenses/cron.aug new file mode 100644 index 0000000..98e8cc9 --- /dev/null +++ b/lenses/cron.aug @@ -0,0 +1,145 @@ +(* +Module: Cron + Parses /etc/cron.d/*, /etc/crontab + +Author: Raphael Pinson <[email protected]> + +About: Reference + This lens tries to keep as close as possible to `man 5 crontab` where + possible. + +About: License + This file is licensed under the GPL. + +About: Lens Usage + Sample usage of this lens in augtool + + * Get the identifier of the devices with a "Clone" option: + > match "/files/etc/X11/xorg.conf/Device[Option = 'Clone']/Identifier" + +About: Configuration files + This lens applies to /etc/cron.d/* and /etc/crontab. See <filter>. +*) + +module Cron = + autoload xfm + +(************************************************************************ + * Group: USEFUL PRIMITIVES + *************************************************************************) + +(* Group: Generic primitives *) + +(* Variable: eol *) +let eol = Util.eol + +(* Variable: indent *) +let indent = Util.indent + +(* Variable: comment *) +let comment = Util.comment + +(* Variable: empty *) +let empty = Util.empty + +(* Variable: num *) +let num = /[0-9\*][0-9\/,-\*]*/ + +(* Variable: alpha *) +let alpha = /[A-Za-z]{3}/ + +(* Variable: alphanum *) +let alphanum = num | alpha + + +(* Group: Separators *) + +(* Variable: sep_spc *) +let sep_spc = Util.del_ws_spc + +(* Variable: sep_eq *) +let sep_eq = Util.del_str "=" + + + +(************************************************************************ + * Group: ENTRIES + *************************************************************************) + + +(************************************************************************ + * View: shellvar + * A shell variable in crontab + *************************************************************************) + +let shellvar = [ key /[A-Z][A-Za-z0-9]*/ . sep_eq + . Shellvars.simple_value . eol ] + + +(* View: minute *) +let minute = [ label "minute" . store num ] + +(* View: hour *) +let hour = [ label "hour" . store num ] + +(* View: dayofmonth *) +let dayofmonth = [ label "dayofmonth" . store num ] + +(* View: month *) +let month = [ label "month" . store alphanum ] + +(* View: dayofweek *) +let dayofweek = [ label "dayofweek" . store alphanum ] + + +(* View: user *) +let user = [ label "user" . store Rx.word ] + +(* View: command *) +let command = [ label "command" . store Rx.space_in ] + + +(************************************************************************ + * View: time + * Time in the format "minute hour dayofmonth month dayofweek" + *************************************************************************) +let time = minute . sep_spc . hour . sep_spc . dayofmonth + . sep_spc . month . sep_spc . dayofweek + +(* Variable: the valid values for schedules *) +let schedule_re = "reboot" | "yearly" | "annually" | "monthly" + | "weekly" | "daily" | "midnight" | "hourly" + +(************************************************************************ + * View: schedule + * Time in the format "@keyword" + *************************************************************************) +let schedule = [ label "schedule" . Util.del_str "@" + . store schedule_re ] + + +(************************************************************************ + * View: entry + * A crontab entry + *************************************************************************) + +let entry = [ label "entry" . indent + . ( time | schedule ) + . sep_spc . user + . sep_spc . command . eol ] + + +(* + * View: lns + * The cron lens + *) +let lns = ( empty | comment | shellvar | entry )* + + +(* Variable: filter *) +let filter = + incl "/etc/cron.d/*" . + incl "/etc/crontab" . + Util.stdexcl + +let xfm = transform lns filter diff --git a/lenses/tests/test_cron.aug b/lenses/tests/test_cron.aug new file mode 100644 index 0000000..b4d380f --- /dev/null +++ b/lenses/tests/test_cron.aug @@ -0,0 +1,39 @@ +module Test_cron = + + let conf = "# /etc/cron.d/anacron: crontab entries for the anacron package + +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + + 30 7 * * * root test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null + 00 */3 15-25/2 May 1-5 user somecommand +# a comment +...@yearly foo a command\n" + + test Cron.lns get conf = + { "#comment" = "/etc/cron.d/anacron: crontab entries for the anacron package" } + {} + { "SHELL" = "/bin/sh" } + { "PATH" = "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" } + {} + { "entry" + { "minute" = "30" } + { "hour" = "7" } + { "dayofmonth" = "*" } + { "month" = "*" } + { "dayofweek" = "*" } + { "user" = "root" } + { "command" = "test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null" } } + { "entry" + { "minute" = "00" } + { "hour" = "*/3" } + { "dayofmonth" = "15-25/2" } + { "month" = "May" } + { "dayofweek" = "1-5" } + { "user" = "user" } + { "command" = "somecommand" } } + { "#comment" = "a comment" } + { "entry" + { "schedule" = "yearly" } + { "user" = "foo" } + { "command" = "a command" } } _______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
