Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)


"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Sunday August 10, 2003
06:42 PM

Crontab fun

[ #14037 ]
Dear Log,

Crontab is a simple format; but it's surprisingly easy to make a mistake in crontab files. For example, it's surprisingly easy to type this:

4 1,12 * * 3 * thingy --hoohah whathaveyou '*.stuff' /home/thing/stuff

and not immediately see that there's the wrong number of fields there, and that the first command to be run is "*" with parameters "thingy -hoohah whathaveyou '*.stuff' /home/thing/stuff".

Yeah. Oops.

The basic problem is that crontab files are meant to be parsed by one program, cron, but cron doesn't, and can't, do much in the way of prompting for you like "You said A, but that's odd. Did you really mean B? Press Y/n:". And this is a real problem because cron is often used for scheduling Very Important Things, and anyway the whole point of cron is to be able to forget about processes, a purpose which is defeated when you have to remember "Hm, I have to remember to look first thing tomorrow to see whether the cron job I set up for 1am is actually running right."

So I figured that the best that one could do, is to make a sanity-checker for crontab files -- something that test-parses a prospective crontab file and... what? Re-emits it in some other format? I could simply add labels to the fields ("Minute: 4. Hour: 1,2", etc), but that still fails to explain some of the more arcane crontab syntax. So I figure that the most direct thing to do is to just explain it in English. That's how I thought of crontab2english.

The idea is this: Before you put a line in a real crontab file and call "crontab thatfile" on it, you run crontab2english on that file (or, if you want, just on that line). So you write this:

4 1,12 * * 3 * thingy --hoohah whathaveyou '*.stuff' /home/thing/stuff

And it looks fine to you. But, because you are a good drone who avoids disaster by entertaining the possibility that you might make mistakes, you run it past crontab2english, and it says:

Command: (line 1)
  Run: * thingy --hoohah whathaveyou '*.stuff' /home/thing/stuff
   (Do you really mean the command to start with "*"?)
  At: 4 minutes past    1am and noon of    every Wednesday

And that lets you know that while you were puzzling over the man page for thingy to figure out the difference between "--hoohah" and "--badabing", you screwed up the first few crontab fields. So now you can change it to this, or whatever you really meant:

4 1,12 * * 3 thingy --hoohah whathaveyou '*.stuff' /home/thing/stuff

For that, crontab2english says this:

Command: (line 1)
  Run: thingy --hoohah whathaveyou '*.stuff' /home/thing/stuff
  At: 4 minutes past    1am and noon of    every Wednesday

And if that's what you meant, now you can run "crontab thatfile".

And that's why you should use crontab2english. You can download it from my CPAN directory

Of course, it's in Perl.

And no, I'm not going to localize it to any languages other than English, and no I'm not going to write english2crontab. It's too complicated.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.