有没有类似 crontab 的 lint 程序?

发布于 2024-07-12 04:08:59 字数 70 浏览 7 评论 0原文

有没有类似 crontab 的 lint 之类的东西? 我想知道我已经整理好了所有的空间和星星,而无需等待某些东西不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

很糊涂小朋友 2024-07-19 04:08:59

有一个用于 crons 的 Python linter。 请参阅 chkcrontab 项目

您可以通过 pip 安装它:

pip3 install chkcrontab

用法示例:

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.

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.
悸初 2024-07-19 04:08:59

我发现 CronWTF 在编写 crontab 时非常有用 - 它将您的星星和命令转换为更人性化的东西,以便更轻松地阅读奇怪的 cron 作业。

更好的是,因为它都是 javascript,所以您可以在本地运行它,并且没有人需要知道您的顶级 sekrit cron 作业。

如果您编写 ruby​​ 代码,另一种选择是使用 whenever gem -您使用一个名为 schedule.rb 的示例 ruby​​ 文件来解析并生成 crontab,如下所示:

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

将为您提供一个 crontab 条目

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

而这里的这个:

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

将为您提供:

30 4 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /usr/bin/my_great_command

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
何时共饮酒 2024-07-19 04:08:59

我认为你不需要 crontab 的 lint。 有 5 个字段,它们以空格分隔,然后是一个空格,然后是要运行的命令及其参数。

另外,至少在 Ubuntu 上,crontab 不会让你保存 bum 文件。 我只是尝试了一些东西,但它们都吐了。 我想这意味着 crontab 是它自己的“cron 的 lint”。

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

悍妇囚夫 2024-07-19 04:08:59

它可能有点偏离,但一个简单的方法是使用图形 crontab 编辑器(如 kcron 或 gcrontab)加载它。 如果您需要在脚本中调用它,这个问题是关于如何执行的在 PHP 中。

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.

迟月 2024-07-19 04:08:59

我不确定这是否是您正在寻找的东西,但它通过准确地向您显示您将计划设置为的内容,使编写 crontab 变得非常容易:

https://crontab.guru/

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/

吾家有女初长成 2024-07-19 04:08:59

您可以尝试 Wicked Cool Shell Scripts, 2nd Edition48-verifycron 的 shell 脚本>,
如果您无法访问 python 和 pip 来使用 chkcrontab

You can try shell script named 48-verifycron from Wicked Cool Shell Scripts, 2nd Edition,
if you can't access python and pip to use chkcrontab

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文