可以创建自己的crontab特殊字符串吗?

huangapple go评论46阅读模式
英文:

Is it possible to create my own crontab special string?

问题

计划任务程序包括八个以“@”开头的特殊字符串:@reboot@yearly等... (man 5 crontab)。我想创建自己的:@five_minutes = */5 * * * *

但是否有办法在crontab中创建新的特殊字符串?

英文:

The cron daemon includes eight special strings, starting with "@" : @reboot, @yearly etc... (man 5 crontab). And I would like to create my own: @five_minutes = */5 * * * *.

But is there a way to create new special strings in crontab?

答案1

得分: 0

不,语法不允许这样做。

也许你可以为你的格式编写一个简单的解析器,然后从中生成你实际的 crontab

sed 's%^@five_minutes%*/5 * * * *%' crontab.in | crontab -

对于这个特定的简单用例,学习正确的语法似乎是一个更简单和更可靠的解决方案。

英文:

No, the syntax does not allow anything like this.

Perhaps you could write a simple parser for your format, and generate your actual crontab from that.

sed 's%^@five_minutes%*/5 * * * *%' crontab.in | crontab -

For this particular simple use case, learning the proper syntax seems like a much simpler and more robust solution.

huangapple
  • 本文由 发表于 2023年5月17日 16:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定