views:

198

answers:

3

Is there anything like lint for crontab? I'd like to know that i've got all my spaces and stars sorted out without waiting for something to not work.

A: 

It might be a bit off, but an easy way would be to just load it with a graphical crontab editor like kcron or gcrontab. If you need to call it in a script, this question is about how to do it in php.

phihag
ssh admin@myhost kcronError: cannot open displayNot everyone has a GUI.
Adam Hawes
Well, you almost certainly have a GUI somewhere. Use ssh X forwarding and voilà - The window appears on your screen
phihag
Not if you're on one of my servers it won't. Installing enough X libs (plus GTK/Qt/KDElibs/etc) to get a graphical editor is a no-no on a serious server. Size reasons aside, we like to keep off everything that can present a possible attack vector.
Adam Hawes
+2  A: 

I don't think you need a lint for crontab. There's 5 fields that are space separated then a space then the command to run and its args finish off the line.

Also, on Ubuntu at least, crontab won't let you save a bum file. I just tried a few things and it barfed on all of them. I guess that means that crontab is its own 'lint for cron'.

Adam Hawes
+1  A: 

I've found CronWTF to be incredibly helpful when writing crontabs - it translates your stars and commands into something more human friendly, to make it easier to read strange cron jobs.

Better yet, because it's all javascript you can run it locally, and noone need know about your top sekrit cron jobs.

Another alternative if you code ruby is to use the whenever gem - you use a sample ruby file called schedule.rb to parse, and generate crontabs from like so:

every 10.minutes do
  command "/usr/bin/my_great_command" 
end

Will give you a crontab entry of

0,10,20,30,40,50 * * * * /usr/bin/my_great_command

And this one here:

every 2.days, :at => '4:30am' do
  command "/usr/bin/my_great_command" 
end

Will give you:

30 4 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /usr/bin/my_great_command
Chris Adams
ooo those are both nifty! thanks
Uberfuzzy