Question

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.

Was it helpful?

Solution

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'.

OTHER TIPS

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

There's a Python linter for crons. See the CheckCrontab project

I'm not sure if this is the sort of thing you're looking for, but it makes writing crontabs really easy by showing you exactly what you're setting the schedule to:

https://crontab.guru/

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top