mcron.texi 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. \input texinfo
  2. @c %**start of header
  3. @setfilename mcron.info
  4. @include config.texi
  5. @include version.texi
  6. @settitle mcron @value{VERSION}
  7. @c %**end of header
  8. @syncodeindex fn cp
  9. @copying This manual is for GNU mcron (version @value{VERSION}), which is a
  10. program for running jobs at scheduled times.
  11. Copyright @copyright{} 2003, 2005, 2006, 2012, 2014 Dale Mellor
  12. Copyright @copyright{} 2018 Mathieu Lirzin
  13. Copyright @copyright{} 2021 Maxim Cournoyer
  14. @quotation
  15. Permission is granted to copy, distribute and/or modify this
  16. document under the terms of the GNU Free Documentation License,
  17. Version 1.3 or any later version published by the Free Software
  18. Foundation; with no Invariant Sections, no Front-Cover Texts and
  19. no Back-Cover Texts. A copy of the license is included in the
  20. section entitled ``GNU Free Documentation License''.
  21. @end quotation
  22. @end copying
  23. @ifinfo
  24. @dircategory Individual utilities
  25. @direntry
  26. * mcron: (mcron). Run jobs at scheduled times.
  27. @end direntry
  28. @end ifinfo
  29. @titlepage
  30. @title mcron - Mellor's cron daemon
  31. @author Dale Mellor
  32. @page
  33. @vskip 0pt plus 1fill
  34. @c @insertcopying
  35. @end titlepage
  36. @contents
  37. @ifnottex
  38. @node Top, Introduction, (dir), (dir)
  39. @top mcron
  40. This file documents the @code{mcron} command (Mellor's cron) for
  41. running jobs at scheduled times.
  42. @c @insertcopying
  43. @end ifnottex
  44. @menu
  45. * Introduction:: Introducing mcron.
  46. * Simple examples:: How to use mcron 99.9% of the time.
  47. * Syntax:: All the possibilities for configuring cron jobs.
  48. * Invoking:: What happens when you run the mcron command.
  49. * Guile modules:: Incorporating mcron into another Guile program.
  50. * GNU Free Documentation License:: The license of this manual.
  51. * Index:: The complete index.
  52. @detailmenu
  53. --- The Detailed Node Listing ---
  54. Simple examples
  55. * Guile Simple Examples::
  56. * Vixie Simple Examples::
  57. Full available syntax
  58. * Guile Syntax::
  59. * Extended Guile examples::
  60. * Vixie Syntax::
  61. Extended Guile examples
  62. * AT commands::
  63. * Every second Sunday::
  64. * Two hours every day::
  65. * Missing the first appointment::
  66. * Penultimate day of every month::
  67. Vixie
  68. * Paul Vixie's copyright::
  69. * Crontab file::
  70. * Incompatibilities with old Unices::
  71. Detailed invoking
  72. * Invoking mcron::
  73. * Invoking cron or crond::
  74. * Invoking crontab::
  75. * Behaviour on laptops::
  76. * Exit codes::
  77. Guile modules
  78. * The base module:: The job list and execution loop.
  79. * The redirect module:: Sending output of jobs to a mail box.
  80. * The vixie-time module:: Parsing vixie-style time specifications.
  81. * The job-specifier module:: All commands for scheme configuration files.
  82. * The vixie-specification module:: Commands for reading vixie-style crontabs.
  83. @end detailmenu
  84. @end menu
  85. @node Introduction, Simple examples, Top, Top
  86. @chapter Introducing mcron
  87. @cindex introduction
  88. @cindex mcron
  89. The mcron program represents a complete re-think of the cron concept
  90. originally found in the Berkeley and AT&T unices, and subsequently
  91. rationalized by Paul Vixie. The original idea was to have a daemon
  92. that wakes up every minute, scans a set of files under a special
  93. directory, and determines from those files if any shell commands
  94. should be executed in this minute.
  95. The new idea is to read the required command instructions, work out
  96. which command needs to be executed next, and then sleep until the
  97. inferred time has arrived. On waking the commands are run, and the
  98. time of the next command is computed. Furthermore, the specifications
  99. are written in scheme, allowing at the same time simple command
  100. execution instructions and very much more flexible ones to be composed
  101. than the original Vixie format. This has several useful advantages
  102. over the original idea. (Changes to user crontabs are signalled
  103. directly to mcron by the crontab program; cron must still scan the
  104. /etc/crontab file once every minute, although use of this file is
  105. highly discouraged and this behaviour can be turned off).
  106. @cindex advantages of mcron
  107. @itemize @bullet
  108. @item
  109. Does not consume CPU resources when not needed. Many cron daemons only
  110. run jobs once an hour, or even just once a day.
  111. @item
  112. Can easily allow for finer time-points to be specified,
  113. i.e. seconds. In principle this could be extended to microseconds, but
  114. this is not implemented.
  115. @item
  116. Times can be more or less regular. For example, a job that runs
  117. every 17 hours can be specified, or a job that runs on the first
  118. Sunday of every month.
  119. @item
  120. Times can be dynamic. Arbitrary Guile (scheme) code can be provided to
  121. compute the next time that a command needs to be run. This could, for
  122. example, take the system load into consideration.
  123. @item
  124. Turns out to be easy to provide complete backwards compatibility with
  125. Vixie cron.
  126. @item
  127. Each user looks after their own files in their own directory. They can use
  128. more than one to break up complicated cron specifications.
  129. @item
  130. Each user can run their own daemon. This removes the need for suid
  131. programs to manipulate the crontabs, and eliminates many security
  132. concerns that surround all existing cron programs.
  133. @item
  134. The user can obtain an advance schedule of all the jobs that are due
  135. to run.
  136. @item
  137. Vixie cron is implemented in 4500 lines of C code; mcron is 2000 lines
  138. of scheme, despite the fact that it offers many more features and much
  139. more flexibility, and complete compatibility with Vixie cron.
  140. @end itemize
  141. A full discussion of the design and philosophy of mcron can be found
  142. in the white paper at
  143. @url{http://www.gnu.org/software/mcron/design.html}.
  144. @node Simple examples, Syntax, Introduction, Top
  145. @chapter Simple examples
  146. The vast majority of uses of cron are sublimely simple: run a program
  147. every hour, or every day. With this in mind the design of mcron has
  148. been to allow such simple specifications to be made easily. The
  149. examples show how to create the command descriptions, and subsequently
  150. how to run mcron to make them happen.
  151. @menu
  152. * Guile Simple Examples::
  153. * Vixie Simple Examples::
  154. @end menu
  155. @node Guile Simple Examples, Vixie Simple Examples, Simple examples, Simple examples
  156. @section Guile
  157. @cindex guile examples
  158. @cindex examples, guile
  159. @cindex example, run a program every hour
  160. You have an executable @code{my-program} in your home directory, which
  161. you want to run every hour. Create a file @code{job.guile} in
  162. directory @code{~/.config/cron} (this path may be altered by the
  163. @code{$XDG_CONFIG_HOME} environment variable) with the following
  164. contents
  165. @example
  166. (job '(next-hour) "my-program")
  167. @end example
  168. then run the command @code{mcron}.
  169. Want the program to run fifteen minutes past the hour, every two
  170. hours? Edit the file to read
  171. @example
  172. (job
  173. '(next-minute-from
  174. (next-hour (range 0 24 2))
  175. 15)
  176. "my-program")
  177. @end example
  178. and run the command @code{mcron}.
  179. Or, if you are not comfortable with Scheme, you could use (and see
  180. also the next section)
  181. @example
  182. (job "15 */2 * * *" "my-program")
  183. @end example
  184. and run the @code{mcron} command.
  185. If you want to run other jobs, you can either add more lines to this
  186. file, or you can create other files in your @code{.config/cron} directory
  187. with the @code{.guile} extension. Alternatively, you can use any file
  188. you want and pass it as an argument to @code{mcron}, or even pipe the
  189. commands into the standard input.
  190. @node Vixie Simple Examples, , Guile Simple Examples, Simple examples
  191. @section Vixie
  192. @cindex examples
  193. @cindex examples, vixie
  194. @cindex vixie examples
  195. You have an executable @code{my-program} in your home directory, which
  196. you want to run every hour. Create a file @code{job.vixie} in directory
  197. @code{~/.cron} with the following contents
  198. @example
  199. 0 * * * * my-program
  200. @end example
  201. then run the command @code{mcron}.
  202. @cindex vixie compatibility
  203. @cindex compatibility
  204. Alternatively (full compatibility with Vixie cron), set your
  205. environment variable @code{EDITOR} to your favorite editor, run
  206. @code{crontab -e}, put the above line into the edit buffer, save and
  207. exit. For this to work the @code{cron} daemon must be already running
  208. on your system, as root.
  209. @node Syntax, Invoking, Simple examples, Top
  210. @chapter Full available syntax
  211. @menu
  212. * Guile Syntax::
  213. * Extended Guile examples::
  214. * Vixie Syntax::
  215. @end menu
  216. @node Guile Syntax, Extended Guile examples, Syntax, Syntax
  217. @section Guile Syntax
  218. @subsection Job specification
  219. @cindex guile syntax
  220. @cindex syntax, guile
  221. @findex job
  222. In Guile-formatted configuration files each command that needs executing is
  223. introduced with the @code{job} function. This function always takes two
  224. arguments, the first a time specification, and the second a command
  225. specification. An optional third argument may contain a string to display
  226. when this job is listed in a schedule. Additionally a @var{user} keyword
  227. argument can be supplied to use a different user than the one defined in
  228. @code{configuration-user} global variable.
  229. @cindex time specification, procedure
  230. @cindex procedure time specification
  231. The first argument can be a procedure, a list, or a string. If a
  232. function is supplied, it must take exactly one argument, which will be
  233. the ``current'' time in UNIX format, and the return value of the
  234. function must be the time in UNIX format when this action should next
  235. be run. The following functions are available to facilitate the
  236. computation:
  237. @findex next-second-from
  238. @code{(next-second-from time . args)} without arguments this
  239. returns the second after the current one. With the extra arguments,
  240. these form a list of seconds in the minute when the action should run,
  241. and the function will return the time of the next allowed second
  242. (which may be in the next minute of the hour). @footnote{Note that
  243. while commands can be scheduled to run at any second, it is unlikely
  244. that they will be executed then but some time shortly thereafter,
  245. depending on the load on the system and the number of jobs that mcron
  246. has to start at the same time.}
  247. @findex next-minute-from
  248. @findex next-hour-from
  249. @findex next-day-from
  250. @findex next-week-from
  251. @findex next-month-from
  252. @findex next-year-from
  253. Similarly to @code{next-second-from}, there are also
  254. @code{next-minute-from}, @code{next-hour-from}, @code{next-day-from},
  255. @code{next-week-from}, @code{next-month-from}, @code{next-year-from}.
  256. @findex range
  257. Furthermore, the optional argument can be fulfilled by the function
  258. @code{(range start end . step)}, which will provide a list of values
  259. from start to (but not including) end, with the step if given. For
  260. example @code{(range 0 10 2)} will yield the list @code{'(0 2 4 6 8)}.
  261. @findex next-second
  262. @findex next-minute
  263. @findex next-hour
  264. @findex next-day
  265. @findex next-week
  266. @findex next-month
  267. @findex next-year
  268. @cindex time specification, list
  269. @cindex list time specification
  270. If the first argument to the @code{job} function is a list, it is
  271. taken to be program code made up of the functions @code{(next-second
  272. . args)}, @code{(next-minute...)}, etc, where the optional arguments
  273. can be supplied with the @code{(range)} function above (these
  274. functions are analogous to the ones above except that they implicitly
  275. assume the current time; it is supplied by the mcron base when the
  276. list is eval'd).
  277. @cindex time specification
  278. @cindex time specification, string
  279. @cindex string time specification
  280. @cindex time specification, vixie-style
  281. @cindex vixie-style time specification
  282. If the first argument to the @code{job} function is a string, it is
  283. expected to be a Vixie cron-style time specification. See the section
  284. on Vixie syntax for this.
  285. @cindex job execution
  286. @cindex command execution
  287. @cindex execution
  288. The second argument to the @code{(job)} function can be either a string, a
  289. list, or a function. The command is executed in the home directory and with
  290. the UID of @var{user}. If a string is passed, it is assumed to be shell
  291. script and is executed with the user's default shell. If a list is passed it
  292. is assumed to be scheme code and is eval'd as such. A supplied function
  293. should take exactly zero arguments, and will be called at the pertinent times.
  294. @subsection Sending output as e-mail
  295. @cindex email output
  296. @cindex email from guile script
  297. @cindex standard input to commands
  298. @findex with-mail-out
  299. When jobs are specified in a vixie-style configuration, the command is
  300. broken at a percentage sign, and the stuff that comes after this is
  301. sent into the command's standard input. Furthermore, any output from
  302. the command is mailed to the user. This functionality is provided for
  303. compatibility with Vixie cron, but it is also available to scheme
  304. configuration files. The command (with-mail-out action . user) can be
  305. used to direct output from the action (which may be a procedure, list,
  306. or string) into an e-mail to the user.
  307. In the case that the action is a string, then percentage signs are
  308. processed as per the vixie specifications, and information is piped to
  309. the shell command's standard input.
  310. @subsection Setting environment variables
  311. @cindex environment variables in scheme
  312. @cindex setting environment variables
  313. @findex append-environment-mods
  314. Also for compatibility with Vixie cron, mcron has the ability to set
  315. environment variables in configuration files. To access this
  316. functionality from a scheme configuration file, use the command
  317. (append-environment-mods name value), where name is the name of an
  318. environment variable, and value is the value put to it. A value of #f
  319. will remove the variable from the environment.
  320. Note that environment modifications are accumulated as the
  321. configuration file is processed, so when a job actually runs, its
  322. environment will be modified according to the modifications specified
  323. before the job specification in the configuration file.
  324. @node Extended Guile examples, Vixie Syntax, Guile Syntax, Syntax
  325. @section Extended Guile examples
  326. @cindex examples, extended guile
  327. @cindex extended guile examples
  328. While Guile gives you flexibility to do anything, and the power to
  329. represent complex requirements succinctly, things are not always as
  330. they seem. The following examples illustrate some pitfalls, and
  331. demonstrate how to code around them.
  332. @menu
  333. * AT commands::
  334. * Every second Sunday::
  335. * Two hours every day::
  336. * Missing the first appointment::
  337. * Penultimate day of every month::
  338. @end menu
  339. @node AT commands, Every second Sunday, Extended Guile examples, Extended Guile examples
  340. @subsection Synthesizing ``at'' commands
  341. @cindex at command
  342. The current implementation of mcron does not provide for an at command
  343. (a command-line program that allows the user to specify that a job
  344. runs exactly once at a certain time). This can, however, be achieved.
  345. Suppose the program @code{my-program} needs to be run at midnight
  346. tonight. A Guile script like the following would work (but a printed
  347. schedule, obtained with the @code{--schedule} option, will show
  348. superfluous entries).
  349. @example
  350. (job '(next-day)
  351. (lambda () (system "my-program")
  352. (kill (getppid) SIGINT)))
  353. @end example
  354. @node Every second Sunday, Two hours every day, AT commands, Extended Guile examples
  355. @subsection Every second Sunday
  356. @cindex examples, every second sunday
  357. To run @code{my-program} on the second Sunday of every month, a Guile
  358. script like the following should suffice (it is left as an exercise to
  359. the student to understand how this works!).
  360. @example
  361. (job (lambda (current-time)
  362. (let* ((next-month (next-month-from current-time))
  363. (first-day (tm:wday (localtime next-month)))
  364. (second-sunday (if (eqv? first-day 0)
  365. 7
  366. (- 14 first-day))))
  367. (+ next-month (* 24 60 60 second-sunday))))
  368. "my-program")
  369. @end example
  370. @node Two hours every day, Missing the first appointment, Every second Sunday, Extended Guile examples
  371. @subsection Two hours every day
  372. @cindex examples, two hours every day
  373. @cindex pitfalls, two hours every day
  374. Surprisingly perhaps, the following will @strong{not} have the desired
  375. effect.
  376. @example
  377. (job '(next-hour-from (next-day) '(1 2))
  378. "my-program")
  379. @end example
  380. Rather than running the my-program program at one o'clock and two
  381. o'clock every day, it will only run it at one o'clock. This is because
  382. each time mcron has to compute the next time to run the command, it
  383. first obtains the next day, and then finds the earliest hour in that
  384. day to run at. Thus, after running the command at one o'clock, the
  385. program first skips forwards to the next midnight (missing the two
  386. o'clock appointment), and then finds the next one o'clock schedule.
  387. The following simple command is the correct way to specify this
  388. behaviour.
  389. @example
  390. (job '(next-hour '(1 2)) "my-program")
  391. @end example
  392. @node Missing the first appointment, Penultimate day of every month, Two hours every day, Extended Guile examples
  393. @subsection Missing the first appointment
  394. @cindex examples, missing the first appointment
  395. @cindex pitfalls, missing the first appointment
  396. The command
  397. @example
  398. (job '(next-hour-from (next-day) '(16))
  399. "my-program")
  400. @end example
  401. will run @code{my-program} every day at four o'clock in the
  402. afternoon. However, if mcron is started with this script at midday,
  403. the first time the command will run will be four o'clock tomorrow;
  404. today's appointment will be missed (one time only).
  405. The correct way to specify this requirement is simply
  406. @example
  407. (job '(next-hour '(16))
  408. "my-program")
  409. @end example
  410. @node Penultimate day of every month, , Missing the first appointment, Extended Guile examples
  411. @subsection Penultimate day of every month
  412. @cindex examples, penultimate day of every month
  413. The following will run the @code{my-program} program on the
  414. second-to-last day of every month.
  415. @example
  416. (job '(- (next-month-from (next-month)) (* 48 3600))
  417. "my-program")
  418. @end example
  419. @node Vixie Syntax, , Extended Guile examples, Syntax
  420. @section Vixie
  421. @cindex syntax, vixie
  422. @cindex vixie syntax
  423. @cindex vixie definition
  424. @cindex vixie compatibility
  425. @cindex compatibility, vixie
  426. @emph{NOTE} that this section is definitive. If there is a difference in
  427. behaviour between the mcron program and this part of the manual, then
  428. there is a bug in the program. This section is also copied verbatim
  429. from Paul Vixie's documentation for their cron program, and their
  430. copyright notice is duly reproduced below.
  431. There are three problems with this specification.
  432. @cindex zero'th day of month
  433. @cindex 0'th day of month
  434. 1. It is allowed to specify days of the month in the range 0-31. What
  435. does it mean to specify day 0? Looking at the Vixie source code, it
  436. seems that if this date appears as part of a list, it has no
  437. effect. However, if it appears on its own, the effect is to say
  438. ``don't run on any particular day of the month, only take the week-day
  439. specification into account.'' Mcron has been coded to mimic this
  440. behaviour as a special case (unmodified mcron logic implies that this
  441. date specification would cause jobs to run on the last day of the
  442. previous month).
  443. @cindex thirteenth month of year
  444. @cindex 13th month of year
  445. 2. Similarly to the above (but different), months of the year can be
  446. specified in the range 0-12. In the case of mcron (don't know what
  447. Vixie cron did) month 12 will cause the program to wait until January
  448. of the following year (but don't rely on this).
  449. @cindex shell
  450. @cindex environment variables, shell
  451. @cindex /etc/passwd
  452. 3. Somewhere it says that cron sets the SHELL environment variable to
  453. /bin/sh, and elsewhere it implies that the default behaviour is for
  454. the user's default shell to be used to execute commands. Mcron sets
  455. the variable and runs the command in the user's default shell, as
  456. advertised by the /etc/passwd file.
  457. @menu
  458. * Paul Vixie's copyright::
  459. * Crontab file::
  460. * Incompatibilities with old Unices::
  461. @end menu
  462. @node Paul Vixie's copyright, Crontab file, Vixie Syntax, Vixie Syntax
  463. @subsection Paul Vixie's copyright
  464. @cindex copyright, Paul Vixie's
  465. @cindex Paul Vixie's copyright
  466. @quotation
  467. Copyright 1988,1990,1993,1994 by Paul Vixie
  468. All rights reserved
  469. Distribute freely, except: don't remove my name from the source or
  470. documentation (don't take credit for my work), mark your changes (don't
  471. get me blamed for your possible bugs), don't alter or remove this
  472. notice. May be sold if buildable source is provided to buyer. No
  473. warrantee of any kind, express or implied, is included with this
  474. software; use at your own risk, responsibility for damages (if any) to
  475. anyone resulting from the use of this software rests entirely with the
  476. user.
  477. @end quotation
  478. @node Crontab file, Incompatibilities with old Unices, Paul Vixie's copyright, Vixie Syntax
  479. @subsection Crontab files
  480. @cindex crontab file
  481. @cindex vixie crontab file
  482. A @code{crontab} file contains instructions to the @code{cron} daemon
  483. of the general form: ``run this command at this time on this date''.
  484. Each user has their own crontab, and commands in any given crontab
  485. will be executed as the user who owns the crontab. Uucp and News will
  486. usually have their own crontabs, eliminating the need for explicitly
  487. running @code{su} as part of a cron command.
  488. @cindex comments, vixie-style
  489. Blank lines and leading spaces and tabs are ignored. Lines whose first
  490. non-space character is a pound-sign (#) are comments, and are ignored.
  491. Note that comments are not allowed on the same line as cron commands, since
  492. they will be taken to be part of the command. Similarly, comments are not
  493. allowed on the same line as environment variable settings.
  494. An active line in a crontab will be either an environment setting or a cron
  495. command. An environment setting is of the form,
  496. @cindex environment setting, vixie-style
  497. @example
  498. name = value
  499. @end example
  500. where the spaces around the equal-sign (=) are optional, and any
  501. subsequent non-leading spaces in @code{value} will be part of the
  502. value assigned to @code{name}. The @code{value} string may be placed
  503. in quotes (single or double, but matching) to preserve leading or
  504. trailing blanks.
  505. @cindex environment variables, SHELL
  506. @cindex environment variables, LOGNAME
  507. @cindex environment variables, HOME
  508. @cindex SHELL environment variable
  509. @cindex LOGNAME environment variable
  510. @cindex HOME environment variable
  511. @cindex /etc/passwd
  512. Several environment variables are set up automatically by the
  513. @code{cron} daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are
  514. set from the /etc/passwd line of the crontab's owner. HOME and SHELL
  515. may be overridden by settings in the crontab; LOGNAME may not.
  516. @cindex environment variables, USER
  517. @cindex USER environment variable
  518. @cindex BSD
  519. (Another note: the LOGNAME variable is sometimes called USER on BSD systems...
  520. on these systems, USER will be set also.) @footnote{mcron has not been
  521. ported to BSD, so these notes are not relevant.}
  522. @cindex environment variables, MAILTO
  523. @cindex MAILTO environment variable
  524. In addition to LOGNAME, HOME, and SHELL, @code{cron} will look at
  525. MAILTO if it has any reason to send mail as a result of running
  526. commands in ``this'' crontab. If MAILTO is defined (and non-empty),
  527. mail is sent to the user so named. If MAILTO is defined but empty
  528. (MAILTO=""), no mail will be sent. Otherwise mail is sent to the
  529. owner of the crontab. This option is useful if you decide on
  530. /bin/mail instead of /usr/lib/sendmail as your mailer when you install
  531. cron -- /bin/mail doesn't do aliasing, and UUCP usually doesn't read
  532. its mail.
  533. The format of a cron command is very much the V7 standard, with a number of
  534. upward-compatible extensions. Each line has five time and date fields,
  535. followed by a user name if this is the system crontab file,
  536. followed by a command. Commands are executed by @code{cron}
  537. when the minute, hour, and month of year fields match the current
  538. time, @strong{and} when at least one of the two day fields (day of month, or day of week)
  539. match the current time (see ``Note'' below). @code{cron} examines cron entries once every minute.
  540. The time and date fields are:
  541. @cindex vixie time specification fields
  542. @cindex fields, vixie time specification
  543. @multitable @columnfractions .2 .5
  544. @item Field @tab Allowed values
  545. @item ----- @tab --------------
  546. @item minute @tab 0-59
  547. @item hour @tab 0-23
  548. @item day of month @tab 0-31
  549. @item month @tab 0-12 (or names, see below)
  550. @item day of week @tab 0-7 (0 or 7 is Sun, or use names)
  551. @end multitable
  552. A field may be an asterisk (*), which always stands for ``first-last''.
  553. @cindex ranges in vixie time specifications
  554. Ranges of numbers are allowed. Ranges are two numbers separated
  555. with a hyphen. The specified range is inclusive. For example,
  556. 8-11 for an ``hours'' entry specifies execution at hours 8, 9, 10
  557. and 11.
  558. @cindex lists in vixie time specifications
  559. Lists are allowed. A list is a set of numbers (or ranges)
  560. separated by commas. Examples: ``1,2,5,9'', ``0-4,8-12''.
  561. @cindex steps in vixie time specifications
  562. Step values can be used in conjunction with ranges. Following
  563. a range with ``/<number>'' specifies skips of the number's value
  564. through the range. For example, ``0-23/2'' can be used in the hours
  565. field to specify command execution every other hour (the alternative
  566. in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22''). Steps are
  567. also permitted after an asterisk, so if you want to say ``every two
  568. hours'', just use ``*/2''.
  569. @cindex names in vixie-style time specifications
  570. Names can also be used for the ``month'' and ``day of week''
  571. fields. Use the first three letters of the particular
  572. day or month (case doesn't matter). Ranges or
  573. lists of names are not allowed. @footnote{Mcron allows any alphabetic
  574. characters after a name, so full names of days or months are also valid.}
  575. @cindex % character on vixie-style commands
  576. @cindex standard input, vixie-style
  577. The ``sixth'' field (the rest of the line) specifies the command to be
  578. run.
  579. The entire command portion of the line, up to a newline or %
  580. character, will be executed by /bin/sh or by the shell
  581. specified in the SHELL variable of the cronfile.
  582. Percent-signs (%) in the command, unless escaped with backslash
  583. (\\), will be changed into newline characters, and all data
  584. after the first % will be sent to the command as standard
  585. input.
  586. @cindex day specification, vixie-style
  587. @cindex vixie-style day specification
  588. Note: The day of a command's execution can be specified by two
  589. fields -- day of month, and day of week. If both fields are
  590. restricted (ie, aren't *), the command will be run when
  591. @emph{either}
  592. field matches the current time. For example,
  593. ``30 4 1,15 * 5''
  594. would cause a command to be run at 4:30 am on the 1st and 15th of each
  595. month, plus every Friday.
  596. EXAMPLE CRON FILE
  597. @example
  598. # use /bin/sh to run commands, no matter what /etc/passwd says
  599. SHELL=/bin/sh
  600. # mail any output to `paul', no matter whose crontab this is
  601. MAILTO=paul
  602. #
  603. # run five minutes after midnight, every day
  604. 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
  605. # run at 2:15pm on the first of every month -- output mailed to paul
  606. 15 14 1 * * $HOME/bin/monthly
  607. # run at 10 pm on weekdays, annoy Joe
  608. 0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
  609. 23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
  610. 5 4 * * sun echo "run at 5 after 4 every sunday"
  611. @end example
  612. @node Incompatibilities with old Unices, , Crontab file, Vixie Syntax
  613. @subsection Extensions and incompatibilities
  614. @cindex incompatibilities with old Unices
  615. @cindex extensions, vixie over old Unices
  616. This section lists differences between Paul Vixie's cron and the
  617. olde-worlde BSD and AT&T programs, for the benefit of system
  618. administrators and users who are upgrading all the way.
  619. @itemize @bullet
  620. @item
  621. @cindex day 7
  622. When specifying day of week, both day 0 and day 7 will be considered Sunday.
  623. BSD and AT&T seem to disagree about this.
  624. @item
  625. Lists and ranges are allowed to co-exist in the same field. "1-3,7-9" would
  626. be rejected by AT&T or BSD cron -- they want to see "1-3" or "7,8,9" ONLY.
  627. @item
  628. Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
  629. @item
  630. Names of months or days of the week can be specified by name.
  631. @item
  632. Environment variables can be set in the crontab. In BSD or AT&T, the
  633. environment handed to child processes is basically the one from /etc/rc.
  634. @item
  635. Command output is mailed to the crontab owner (BSD can't do this), can be
  636. mailed to a person other than the crontab owner (SysV can't do this), or the
  637. feature can be turned off and no mail will be sent at all (SysV can't do this
  638. either).
  639. @end itemize
  640. @node Invoking, Guile modules, Syntax, Top
  641. @chapter Detailed invoking
  642. @cindex invoking
  643. @cindex personality
  644. @cindex mcron program
  645. @cindex cron program
  646. @cindex crond program
  647. @cindex crontab program
  648. The program adopts one of three different personalities depending on
  649. the name used to invoke it. In a standard installation, the program is
  650. installed in the system under the names mcron, cron and crontab
  651. (installed SUID).
  652. The recommended way to invoke the program is via the mcron personality
  653. described in the next section. The program can also be run as cron by
  654. root, and by the SUID program crontab by individual users to gain
  655. backwards compatibility with Vixie cron. However, due to the fact that
  656. this daemon process is shared by, and under control of, all the users
  657. of the system it is possible (though very unlikely) that it may become
  658. unusable, hence the recommendation to use the mcron personality.
  659. @cindex deprecated, vixie personality
  660. Furthermore, the Vixie personality is considered deprecated by this
  661. author (it offers not a single advantage over the mcron personality,
  662. and bloats the code by a factor of three). It is unlikely that this
  663. personality will ever actually go away, but the program may in future
  664. be split into two distinct parts, and new developments will only take
  665. place in the part which implements the mcron personality.
  666. @menu
  667. * Invoking mcron::
  668. * Invoking cron or crond::
  669. * Invoking crontab::
  670. * Behaviour on laptops::
  671. * Exit codes::
  672. @end menu
  673. @node Invoking mcron, Invoking cron or crond, Invoking, Invoking
  674. @section Invoking mcron
  675. @cindex invoking mcron
  676. @cindex mcron options
  677. @cindex mcron arguments
  678. @cindex command line, mcron
  679. @cindex mcron command line
  680. Mcron should be run by the user who wants to schedule their jobs. It
  681. may be made a background job using the facilities of the shell. The
  682. basic command is @code{mcron [OPTION ...] [file ...]} which has the
  683. effect of reading all the configuration files specified (subject to
  684. the options) and then waiting until it is time to execute some
  685. command. If no files are given on the command line, then mcron will
  686. look in the user's cron configuration directories: these are ~/.cron
  687. (deprecated), the directory indicated by the @code{XDG_CONFIG_HOME}
  688. environment variable, or ~/.config/cron if this variable is not set.
  689. In any case, files which end in the extension .vixie or .vix will be
  690. assumed to contain Vixie-style crontabs, and files ending .guile or
  691. .gle will be assumed to contain scheme code and will be executed as
  692. such; ANY OTHER FILES WILL BE IGNORED - specify a file name of ``-''
  693. and then pipe the files into the standard input if you really want to
  694. read them, possibly using the @code{stdin} option to specify the type
  695. of file.
  696. The program accepts the following options.
  697. @table @option
  698. @item -s count
  699. @itemx --schedule=count
  700. @cindex printout of jobs schedule
  701. @cindex schedule of jobs, listing
  702. @cindex options, schedule
  703. @cindex options, -s
  704. @cindex -s option
  705. @cindex --schedule option
  706. With this option specified no commands are run. Instead, the program
  707. computes the times the commands would be run and prints the
  708. information to the screen, and then immediately exits.
  709. The count indicates the number of commands to display.
  710. @cindex daemon option
  711. @cindex options, daemon
  712. @cindex options, -d
  713. @cindex -d option
  714. @cindex --daemon option
  715. @item -d
  716. @itemx --daemon
  717. With this option the program will detach itself from the controlling
  718. terminal and run as a daemon process.
  719. @cindex stdin option
  720. @cindex options, stdin
  721. @cindex options, -i
  722. @cindex -i option
  723. @cindex --stdin option
  724. @cindex standard input, configuring from
  725. @cindex configuring from standard input
  726. @item -i (vixie|guile)
  727. @itemx --stdin=(vixie|guile)
  728. This option is used to indicate whether the configuration information
  729. being passed on the standard input is in Vixie format or Guile
  730. format. Guile is the default.
  731. @cindex log-format option
  732. @cindex options, log-format
  733. @cindex --log-format option
  734. @cindex logging output, configuration
  735. @cindex configuring the logging output
  736. @anchor{--log-format}
  737. @item --log-format
  738. This option accepts an @code{(ice-9 format)} format string that can be used to
  739. customize the appearance of the output. The format string is applied to
  740. @code{format} with the following four arguments:
  741. @enumerate
  742. @item A date/time string.
  743. @item The job process PID (as as number).
  744. @item The action name.
  745. @item The message to log.
  746. @end enumerate
  747. It defaults to @code{"~a ~2@*~a: ~a~%"}, which produces output messages like:
  748. @example
  749. 2021-08-17T12:01:01 some-job: completed in 0.218s
  750. @end example
  751. If you'd rather see the job process PID instead of a timestamp, you could
  752. instead specify the format string as @code{"~1@*~a ~a: ~a~%"}, which would
  753. result in something like:
  754. @example
  755. 39234 some-job: completed in 0.218s
  756. @end example
  757. To learn about all the possibilities offered by @code{(ice-9 format)}, refer
  758. to @ref{Formatted Output,,, guile, GNU@tie{}Guile@tie{}Reference@tie{}Manual}.
  759. @cindex date-format option
  760. @cindex options, date-format
  761. @cindex --date-format option
  762. @cindex timestamp, modification
  763. @cindex changing the default timestamp
  764. @anchor{--date-format}
  765. @item --date-format
  766. This option accepts a @code{(srfi srfi-19)} date string format, to customize
  767. the appearance of the timestamp in output messages. It defaults to
  768. @code{"~5"}, which corresponds to a local ISO-8601 date/time format
  769. (@pxref{SRFI-19 Date to string,,,
  770. guile,GNU@tie{}Guile@tie{}Reference@tie{}Manual}).
  771. @cindex -v option
  772. @cindex --version option
  773. @cindex options, -v
  774. @cindex options, version
  775. @item -v
  776. @itemx --version
  777. This option causes a message to be printed on the standard output with
  778. information about the version and copyright for the current program.
  779. @cindex -h option
  780. @cindex --help option
  781. @cindex options, -h
  782. @cindex options, --help
  783. @item -h
  784. @itemx --help
  785. This causes a short but complete usage message to be displayed on
  786. standard output.
  787. @end table
  788. @node Invoking cron or crond, Invoking crontab, Invoking mcron, Invoking
  789. @section Invoking cron or crond
  790. @cindex cron, invokation
  791. @cindex invoking cron
  792. @cindex crond, invokation
  793. @cindex invoking crond
  794. @cindex @value{CONFIG_SPOOL_DIR}
  795. @cindex @value{CONFIG_SOCKET_FILE}
  796. NOTE THAT THIS SECTION ONLY APPLIES IF THE @code{cron} or
  797. @code{crond}, and @code{crontab} PROGRAMS HAVE BEEN INSTALLED BY THE
  798. SYSTEM ADMINISTRATOR.
  799. If the program runs by the name of @code{cron} or @code{crond}, then
  800. it will read all the files in @code{@value{CONFIG_SPOOL_DIR}} (which
  801. should only be readable by root) and the file @code{/etc/crontab}, and
  802. then detaches itself from the terminal to live forever as a daemon
  803. process. Additionally, it creates a UNIX socket at
  804. @code{@value{CONFIG_SOCKET_FILE}}, and listens for messages sent to
  805. that socket consisting of a user name whose crontabs have been
  806. changed. In this case, the program will re-read that user's crontab.
  807. This is for correct functioning with the crontab program.
  808. Further, unless the @code{--noetc} option is used, a job is scheduled to run
  809. every minute to check if @code{/etc/crontab} has been modified. If so, this
  810. file will also be re-read.
  811. The options which may be used with this program are as follows.
  812. @table @option
  813. @cindex -v option
  814. @cindex --version option
  815. @cindex options, -v
  816. @cindex options, version
  817. @item -v
  818. @itemx --version
  819. This option causes a message to be printed on the standard output with
  820. information about the version and copyright for the current program.
  821. @cindex -h option
  822. @cindex --help option
  823. @cindex options, -h
  824. @cindex options, --help
  825. @item -h
  826. @itemx --help
  827. This causes a short but complete usage message to be displayed on
  828. standard output.
  829. @item -s [count]
  830. @itemx --schedule[=count]
  831. @cindex printout of jobs schedule
  832. @cindex schedule of jobs, listing
  833. @cindex options, schedule
  834. @cindex options, -s
  835. @cindex -s option
  836. @cindex --schedule option
  837. With this option specified no commands are run. Instead, the program
  838. computes the times the commands would be run and prints the
  839. information to the screen, and then immediately exits.
  840. The count, if supplied, indicates the number of commands to
  841. display. The default value is 8.
  842. @cindex -n option
  843. @cindex --noetc option
  844. @cindex options, -n
  845. @cindex options, --noetc
  846. @item -n
  847. @itemx --noetc
  848. This tells cron not to add a job to the system which wakes up every
  849. minute to check for modifications to @code{/etc/crontab}. It is
  850. recommended that this option be used (and further that the
  851. @code{/etc/crontab} file be taken off the system altogether!)
  852. @item --log-format
  853. Analogous to mcron's @ref{--log-format}.
  854. @item --date-format
  855. Analogous to mcron's @ref{--date-format}.
  856. @end table
  857. @node Invoking crontab, Behaviour on laptops, Invoking cron or crond, Invoking
  858. @section Invoking crontab
  859. @cindex crontab, invoking
  860. @cindex invoking crontab
  861. This program is run by individual users to inspect or modify their
  862. crontab files. If a change is made to the file, then the root daemon
  863. process will be given a kick, and will immediately read the new
  864. configuration. A warning will be issued to standard output if it
  865. appears that a cron daemon is not running.
  866. The command is used as
  867. @code{crontab [-u user] file}
  868. or
  869. @code{crontab [-u user] ( -l | -e | -r )}
  870. Only the root user can use the -u option, to specify the manipulation
  871. of another user's crontab file. In the first instance, the entire
  872. crontab file of the user is replaced with the contents of the
  873. specified file, or standard input if the file is ``-''.
  874. In the latter case, the program behaves according to which of the
  875. (mutually exclusive) options was given (note that the long options are
  876. an mcron extension).
  877. @table @option
  878. @cindex -l option
  879. @cindex list option, crontab
  880. @cindex options, -l
  881. @cindex options, --list
  882. @cindex viewing a crontab
  883. @cindex listing a crontab
  884. @item -l
  885. @itemx --list
  886. Print the user's crontab file to the standard output, and exit.
  887. @cindex -r option
  888. @cindex remove option
  889. @cindex options, -r
  890. @cindex options, --remove
  891. @cindex deleting a crontab
  892. @cindex removing a crontab
  893. @item -r
  894. @item --remove
  895. Delete the user's crontab file, and exit.
  896. @cindex -e option
  897. @cindex edit option
  898. @cindex options, -e
  899. @cindex options, --edit
  900. @cindex editing a crontab
  901. @cindex creating a crontab
  902. @item -e
  903. @item --edit
  904. Using the editor specified in the user's VISUAL or EDITOR environment
  905. variables, allow the user to edit their crontab. Once the user exits the
  906. editor, the crontab is checked for parseability, and if it is okay
  907. then it is installed as the user's new crontab and the daemon is
  908. notified that a change has taken place, so that the new file will
  909. become immediately effective.
  910. @end table
  911. @node Behaviour on laptops, Exit codes, Invoking crontab, Invoking
  912. @section Behaviour on laptops
  913. @cindex laptops
  914. @cindex power suspend
  915. While mcron has not been designed to work anachronistically, the behaviour of
  916. mcron when a laptop emerges from a suspended state is well defined, and the
  917. following description explains what happens in this situation.
  918. When a laptop awakes from a suspended state, all jobs which would have run while
  919. the laptop was suspended will run exactly once immediately (and simultaneously)
  920. when the laptop awakes, and then the next time that those jobs run will be
  921. computed based on the time the laptop was awoken. Any jobs which would not have
  922. run during the suspense period will be unaffected, and will still run at their
  923. proper times.
  924. @node Exit codes, , Behaviour on laptops, Invoking
  925. @section Exit codes
  926. @cindex exit codes
  927. @cindex error conditions
  928. @cindex errors
  929. The following are the status codes returned to the operating system
  930. when the program terminates.
  931. @table @asis
  932. @item 0
  933. No problems.
  934. @item 1
  935. An attempt has been made to start cron but there is already a
  936. @value{CONFIG_PID_FILE} file. If there really is no other cron daemon
  937. running (this does not include invokations of mcron) then you should
  938. remove this file before attempting to run cron.
  939. @item 2
  940. In parsing a guile configuration file, a @code{job} command has been
  941. seen but the second argument is neither a procedure, list or
  942. string. This argument is the job's action, and needs to be specified
  943. in one of these forms.
  944. @item 3
  945. In parsing a guile configuration file, a @code{job} command has been
  946. seen but the first argument is neither a procedure, list or
  947. string. This argument is the job's next-time specification, and needs
  948. to be specified in one of these forms.
  949. @item 4
  950. An attempt to run cron has been made by a user who does not have
  951. permission to access the crontabs in @value{CONFIG_SPOOL_DIR}. These
  952. files should be readable only by root, and the cron daemon must be run
  953. as root.
  954. @item 5
  955. An attempt to run mcron has been made, but there are no jobs to
  956. schedule!
  957. @item 6
  958. The system administrator has blocked this user from using crontab with
  959. the files @value{CONFIG_ALLOW_FILE} and @value{CONFIG_DENY_FILE}.
  960. @item 7
  961. Crontab has been run with more than one of the arguments @code{-l},
  962. @code{-r}, @code{-e}. These are mutually exclusive options.
  963. @item 8
  964. Crontab has been run with the -u option by a user other than
  965. root. Only root is allowed to use this option.
  966. @item 9
  967. An invalid vixie-style time specification has been supplied.
  968. @item 10
  969. An invalid vixie-style job specification has been supplied.
  970. @item 11
  971. A bad line has been seen in /etc/crontab.
  972. @item 12
  973. The last component of the name of the program was not one of
  974. @code{mcron}, @code{cron}, @code{crond} or @code{crontab}.
  975. @item 13
  976. Either none of the user's configuration directories exist, or there is a problem
  977. reading the files there. The configuration directories are ~/.cron
  978. and the directory pointed to by the @code{XDG_CONFIG_HOME} environment
  979. variable, or ~/.config/cron if this is not set.
  980. @c @item 14
  981. @c There is a problem writing to /var/cron/update. This is probably
  982. @c because the crontab program is not installed SUID root, as it should
  983. @c be.
  984. @item 15
  985. Crontab has been run without any arguments at all. There is no default
  986. behaviour in this case.
  987. @item 16
  988. Cron has been run by a user other than root.
  989. @end table
  990. @node Guile modules, Index, Invoking, Top
  991. @chapter Guile modules
  992. Some of the key parts of mcron are implemented as modules so they can
  993. be incorporated into other Guile programs, or even into C-sourced
  994. programs if they are linked against libguile.
  995. It may be, for example, that a program needs to perform house-keeping
  996. functions at certain times of the day, in which case it can spawn
  997. (either fork or thread) a sub-process which uses a built-in
  998. mcron. Another example may be a program which must sleep until some
  999. non-absolute time specified on the Gregorian calendar (the first day
  1000. of next week, for example). Finally, it may be the wish of the user to
  1001. provide a program with the functionality of mcron plus a bit extra.
  1002. The base module maintains mcron's internal job lists, and provides the
  1003. main wait-run-wait loop that is mcron's main function. It also
  1004. introduces the facilities for accumulating a set of environment
  1005. modifiers, which take effect when jobs run.
  1006. @menu
  1007. * The base module:: The job list and execution loop.
  1008. * The redirect module:: Sending output of jobs to a mail box.
  1009. * The vixie-time module:: Parsing vixie-style time specifications.
  1010. * The job-specifier module:: All commands for scheme configuration files.
  1011. * The vixie-specification module:: Commands for reading vixie-style crontabs.
  1012. @end menu
  1013. @node The base module, The redirect module, Guile modules, Guile modules
  1014. @section The base module
  1015. @cindex guile module
  1016. @cindex base module
  1017. @cindex modules, base
  1018. This module may be used by including @code{(use-modules (mcron base))}
  1019. in a program. The main functions are @code{add-job} and
  1020. @code{run-job-loop}, which allow a program to create a list of job
  1021. specifications to run, and then to initiate the wait-run-wait loop
  1022. firing the jobs off at the requisite times. However, before they are
  1023. introduced two functions which manipulate the environment that takes
  1024. effect when a job runs are defined.
  1025. @cindex environment
  1026. The environment is a set of name-value pairs which is built up
  1027. incrementally. Each time the @code{add-job} function is called, the
  1028. environment modifiers that have been accumulated up to that point are
  1029. stored with the new job specification, and when the job actually runs
  1030. these name-value pairs are used to modify the run-time environment in
  1031. effect.
  1032. @deffn{Scheme procedure} append-environment-mods name value
  1033. When a job is run make sure the environment variable @var{name} has
  1034. the value @var{value}.
  1035. @end deffn
  1036. @deffn{Scheme procedure} clear-environment-mods
  1037. This procedure causes all the environment modifiers that have been
  1038. specified so far to be forgotten.
  1039. @end deffn
  1040. @deffn{Scheme procedure} add-job time-proc action displayable @
  1041. configuration-time configuration-user @
  1042. [#:schedule @var{%global-schedule}]
  1043. This procedure adds a job specification to the list of all jobs to
  1044. run. @var{time-proc} should be a procedure taking exactly one argument
  1045. which will be a UNIX time. This procedure must compute the next time
  1046. that the job should run, and return the result. @var{action} should be
  1047. a procedure taking no arguments, and contains the instructions that
  1048. actually get executed whenever the job is scheduled to
  1049. run. @var{displayable} should be a string, and is only for the use of
  1050. humans; it can be anything which identifies or simply gives a clue as
  1051. to the purpose or function of this job. @var{configuration-time} is
  1052. the time from which the first invokation of this job should be
  1053. computed. Finally, @var{configuration-user} should be the passwd entry
  1054. for the user under whose personality the job is to run.
  1055. @end deffn
  1056. @deffn{Scheme procedure} run-job-loop @var{fd-list} @
  1057. [#:schedule @var{%global-schedule}]
  1058. @cindex file descriptors
  1059. @cindex interrupting the mcron loop
  1060. This procedure returns only under exceptional circumstances, but
  1061. usually loops forever waiting for the next time to arrive when a job
  1062. needs to run, running that job, recomputing the next run time, and
  1063. then waiting again. However, the wait can be interrupted by data
  1064. becoming available for reading on one of the file descriptors in the
  1065. fd-list, if supplied. Only in this case will the procedure return to
  1066. the calling program, which may then make modifications to the job list
  1067. before calling the @code{run-job-loop} procedure again to resume execution of
  1068. the mcron base.
  1069. @end deffn
  1070. @deffn{Scheme procedure} remove-user-jobs user @
  1071. [#:schedule @var{%global-schedule}]
  1072. The argument @var{user} should be a string naming a user (their
  1073. login name), or an integer UID, or an object representing the user's passwd
  1074. entry. All jobs on the current job list that are scheduled to be run
  1075. under this personality are removed from the job list.
  1076. @end deffn
  1077. @deffn{Scheme procedure} display-schedule @var{count} [@var{port}] @
  1078. [#:schedule @var{%global-schedule}]
  1079. @cindex schedule of jobs
  1080. This procedure is used to display a textual list of the next COUNT jobs
  1081. to run.
  1082. The argument @var{count} must be an integer value giving the number
  1083. of time-points in the future to report that jobs will run as. Note
  1084. that this procedure is disruptive; if @code{run-job-loop} is called
  1085. after this procedure, the first job to run will be the one after the
  1086. last job that was reported in the schedule report. The report itself
  1087. is returned to the calling program as a string.
  1088. @end deffn
  1089. @defopt %date-format
  1090. @cindex parameters, date format
  1091. @cindex date format parameter
  1092. This parameter holds the @code{(srfi srfi-19)} format string used to produce
  1093. the timestamp found in output messages. It defaults to @code{"~5"}.
  1094. @end defopt
  1095. @deffn{Scheme procedure} validate-date-format @var{fmt}
  1096. @cindex date format validator
  1097. This procedure is used to validate @var{fmt}, a @code{(srfi srfi-19)} format
  1098. string. When @var{fmt} is invalid, an error message is displayed and the
  1099. program is aborted.
  1100. @end deffn
  1101. @defopt %log-format
  1102. @cindex parameters, log format
  1103. @cindex log format parameter
  1104. This parameter holds the @code{(ice-9 format)} format string used to produce
  1105. the output messages. The four arguments applied to format are the timestamp,
  1106. the process PID, the job name and the message. It defaults to @code{"~a
  1107. ~2@*~a: ~a~%"}.
  1108. @end defopt
  1109. @deffn{Scheme procedure} validate-log-format @var{fmt}
  1110. @cindex log format validator
  1111. This procedure is used to validate @var{fmt}, a @code{(ice-9 format)} format
  1112. string. When @var{fmt} is invalid, an error message is displayed and the
  1113. program is aborted.
  1114. @end deffn
  1115. @node The redirect module, The vixie-time module, The base module, Guile modules
  1116. @section The redirect module
  1117. @cindex redirect module
  1118. @cindex modules, redirect
  1119. This module is introduced to a program with the command
  1120. @code{(use-modules (mcron redirect))}.
  1121. This module provides the @code{with-mail-out} function, described
  1122. fully in @ref{Guile Syntax}.
  1123. @node The vixie-time module, The job-specifier module, The redirect module, Guile modules
  1124. @section The vixie-time module
  1125. @cindex vixie-time module
  1126. @cindex modules, vixie-time
  1127. This module is introduced to a program by @code{(use-modules (mcron
  1128. vixie-time))}.
  1129. This module provides a single method for converting a vixie-style time
  1130. specification into a procedure which can be used as the
  1131. @code{next-time-function} to the base @code{add-job} procedure, or to
  1132. the @code{job-specifier} @code{job} procedure. See @ref{Vixie Syntax}
  1133. for full details of the allowed format for the time string.
  1134. @deffn{Scheme procedure} parse-vixie-time time-string
  1135. The single argument @var{time-string} should be a string containing a
  1136. vixie-style time specification, and the return value is the required
  1137. procedure.
  1138. @end deffn
  1139. @node The job-specifier module, The vixie-specification module, The vixie-time module, Guile modules
  1140. @section The job-specifier module
  1141. @cindex job-specifier module
  1142. @cindex modules, job-specifier
  1143. This module is introduced to a program by @code{(use-modules (mcron
  1144. job-specifier))}.
  1145. This module provides all the functions available to user's Guile
  1146. configuration files, namely @code{range}, @code{next-year-from},
  1147. @code{next-year}, @code{next-month-from}, @code{next-month},
  1148. @code{next-day-from}, @code{next-day}, @code{next-hour-from},
  1149. @code{next-hour}, @code{next-minute-from}, @code{next-minute},
  1150. @code{next-second-from}, @code{next-second},
  1151. and last but not least, @code{job}. See @ref{Guile Syntax} for full
  1152. details.
  1153. Once this module is loaded, a scheme configuration file can be used to
  1154. put jobs onto the job list simply by @code{load}ing the file.
  1155. @node The vixie-specification module, , The job-specifier module, Guile modules
  1156. @section The vixie-specification module
  1157. @cindex vixie-specification module
  1158. @cindex modules, vixie-specification
  1159. To use this module, put the command @code{(use-modules (mcron
  1160. vixie-specification))} into your program.
  1161. This module exports a couple of functions for adding jobs to the
  1162. internal job list according to a Vixie-style crontab file.
  1163. @deffn{Scheme procedure} read-vixie-port port . parse-line
  1164. This procedure reads a crontab from the given port, and adds jobs to
  1165. the job list accordingly, taking care of environment specifications
  1166. and comments which may appear in such a file.
  1167. @var{parse-line} should not normally be used, except that if you are
  1168. parsing a (deprecated) @code{/etc/crontab} file with a slightly
  1169. modified syntax, you may pass the value @var{parse-system-vixie-line}
  1170. as the optional argument.
  1171. @end deffn
  1172. @deffn{Scheme procedure} read-vixie-file name . parse-line
  1173. This procedure attempts to open the named file, and if it fails will
  1174. return silently. Otherwise, the behaviour is identical to
  1175. @code{read-vixie-port} above.
  1176. @end deffn
  1177. Once this module has been declared in a program, a crontab file can be
  1178. used to augment the current job list with a call to
  1179. @code{read-vixie-file}.
  1180. @node GNU Free Documentation License
  1181. @appendix GNU Free Documentation License
  1182. @include fdl.texi
  1183. @node Index, , Guile modules, Top
  1184. @unnumbered Index
  1185. @printindex cp
  1186. @bye