News for hackers. Stuff that matters.
Re:Cron checker by jstimpfle on Saturday July 16, 2016 @06:49AM (#12105928)
Crontab is an excellent example of situations where text files are superior. You are welcome to try to design a database schema that is safer or easier to use.

Most of the things living under /etc are not databases. crontab certainly isn't:

- Only a single "table" (no table-relations)

- No standard database type exists for columns (how would you model the scheduling as database types, how would you model the shell command as database types, if not simply as sanitized strings)

So you can't get integrity for free. Need a custom parser and some integrity checks. Not so difficult (yes, cron will give instant feedback for the unlikely case that you did something wrong)

Re: editor, locking, access control:

I have an editor and prefer it to writing SQL DML any day.

File updates (rename(2)) are atomic, so no need for additional locking. And even if there is some broken tool writing to the old file instead of rename, the chances of that being simultaneous with a parse are microscopic. Don't overdesign. (there are many more things that can go wrong in a system that you can't possibly design out. Live with it).

Access control: Standard file permission modes are just fine. More complex permission model would be a serious overdesign. You can get granularity by using separate crontabs.

Checker: Never needed an additional tool to format the meaning as human-readable text. The syntax is a bit ugly but quite easy to remember and use.

Re:Cron checker by cma on Saturday July 16, 2016 @07:26AM (#12105999)
A cron job kicks off that makes the whole system unresponsive, undergoing heavy swap (updatedb used to do this and ran every night on many default systems).

Someone edits a cron file in the most common editor, vim. On many systems it doesn't do an atomic swap on save without extra configuration: http://stackoverflow.com/questions/13563627/how-does-vim-sav...

Now maybe your unresponsive, undergoing swap, system misses a cron job that was present in both edits. Opps.

I'm not sure this could really play out, but the approach definitely sounds firmly on the "worse is better" side of the scale.

Re:Cron checker by krunaldo on Saturday July 16, 2016 @07:36AM (#12106012)
crontab -e is the way to edit your cron. A similar command exists for editing the sudoers file which is visudo. This will ensure your configuration is a valid syntax as well as do an atomic swap of the file.

Otherwise adding a file or deleting a file in /etc/cron.d/ is the way to go for automatic(ansbile, puppet etc) and package installations.

Re:Cron checker by krrrh on Saturday July 16, 2016 @10:11AM (#12106379)
I'm surprised that people would edit cron in any other way, crontab -e is one of the first commands most intro to Linux manuals teaches.

However crontab -r has to be one of the most poorly thought out commands in UNIX. It removes the cron file and since r is only one character over from e on qwerty keyboards it's a painful and surprising typo.

Re:Cron checker by mooneater on Saturday July 16, 2016 @11:16PM (#12108881)
first thing when logging into new server: place /etc under git. then loss of cron files (or any config file) is easily recovered from.
Re:Cron checker by pferde on Sunday July 17, 2016 @03:47AM (#12109397)
Except that crontabs are usually somewhere in /var. :)
Re:Cron checker by mooneater on Sunday July 17, 2016 @10:53PM (#12113010)
Which is why I only use system-wide crontabs, in /etc/cron.d

Instead of per-user crontabs. Much easier to manage.

With cron.d you can specify what user each cron entry should run as, so it is equivalent.

Re:Cron checker by Drdrdrq on Sunday July 17, 2016 @01:37AM (#12109141)
This is a brilliant idea - thank you!
Re:Cron checker by mooneater on Sunday July 17, 2016 @10:55PM (#12113015)
I cannot count the number of times this has helped or saved me. You can keep the /etc git repo local. Or if its a critical server, push to github private repo. Seeing a history of your /etc edits is a very reassuring feeling.
Re:Cron checker by efiala on Saturday July 16, 2016 @10:37AM (#12106456)
what if you are managing the crons externally, eg puppet, crontab -e is not always option
Re:Cron checker by Godel_unicode on Saturday July 16, 2016 @12:01PM (#12106752)
1. If you don't have a test process for changes made with puppet, this is hardly a problem with cron.

2. Puppet handled that parsing for you and will throw errors if your syntax is wrong

Re:Cron checker by _ao789 on Saturday July 16, 2016 @01:09PM (#12107030)
I can't tell you the amount of times I've hit -r by mistake and regretted it..
Re:Cron checker by michaelcampbell on Saturday July 16, 2016 @03:46PM (#12107617)
I can. 0. There, more anecdata.

Honestly though, I never use `-e` either. I keep a ~/.crontab and edit that, and then `crontab ~/.crontab`.

Voila, backup/time machine/git friendly crontab.

Re:Cron checker by benjojo12 on Sunday July 17, 2016 @05:29PM (#12111940)
I got bit by this once, and had to rescue the crontab out off the disk with GNU strings :(
Re:Cron checker by dajohnson89 on Saturday July 16, 2016 @05:14PM (#12107899)
Have a cronjob that backs up your crontab?
Re:Cron checker by hibbelig on Saturday July 16, 2016 @12:54PM (#12106968)
Use /bin/cat as editor. That should work nicely from Puppet.
Re:Cron checker by Animats on Saturday July 16, 2016 @01:38PM (#12107152)
crontab -e is the way to edit your cron. A similar command exists for editing the sudoers file which is visudo. This will ensure your configuration is a valid syntax as well as do an atomic swap of the file.

And there's "vipw" for the password file. Each of them with their own separate updating bugs.

Re:Cron checker by jstimpfle on Saturday July 16, 2016 @07:37AM (#12106016)
"Worse is better" is an oxymoron. You can also read it as "better is worse". In "worse is better", the "worse" isn't really worse in practical settings (considering all tradeoffs, giving appropriate weights to design goals, etc.).

Nobody argues that there can't be problems. What all critics miss is to show how to avoid these problems.

What can you do about jobs that make the system unresponsive? Not a problem for cron to solve.

If someone writes a crontab (instead of rename()ing another version over it), that's not cron's fault. Sqlite databases can be just as easily corrupted or lose integrity. Now which format would you rather repair?

Missing a cron job can not be totally avoided, and it isn't the end of the world. What if your machine goes down or cron crashes? The answer is that the jobs themselves have to be provided with some resilience against that situation.

This isn't a case of "worse is better" since there weren't proposed solutions to the "problems" at all, however unrealistic.

Re:Cron checker by pekeler on Saturday July 16, 2016 @11:44AM (#12106705)
This is a perfect example for why you ought to monitor all your cronjobs with something like https://wdt.io.
Re:Cron checker by cel1ne on Saturday July 16, 2016 @07:04AM (#12105952)
Not all databases follow a relational model with tables or schemas. I guess what he meant is that a key-value store would have some merits over files. Kinda like Window's registry.
Re:Cron checker by jstimpfle on Saturday July 16, 2016 @07:14AM (#12105968)
He explicitly mentioned sqlite. Key-value stores could not improve on that since RDBMS generalize key-value.
Re:Cron checker by Zardoz84 on Saturday July 16, 2016 @08:33AM (#12106136)
Bad example. Windows registry is well know as a source of problems.