Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a lint like program for crontab?

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.

like image 505
Uberfuzzy Avatar asked Jan 26 '09 11:01

Uberfuzzy


3 Answers

There's a Python linter for crons. See chkcrontab project

You can install it via pip:

pip3 install chkcrontab

Example usage:

chkcrontab /etc/cron.d/power-schedule
Checking correctness of /etc/cron.d/power-schedule
E: 15: 0 12 * foo * * root echo hi
e:     FIELD_VALUE_ERROR: foo is not valid for field "month" (foo)
e:     INVALID_USER: Invalid username "*"
E: There were 2 errors and 0 warnings.
like image 97
Adil Avatar answered Oct 29 '22 00:10

Adil


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/

like image 34
Paul Richter Avatar answered Oct 28 '22 22:10

Paul Richter


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
like image 29
Chris Adams Avatar answered Oct 28 '22 23:10

Chris Adams