我需要在 bash 中检查 crontab 文件中的条目是否有效。有crontab
命令开关吗?
我可以提取单个行并尝试通过正则表达式控制单个项目,但我不知道如何检查记录类型,例如10,20,30
, */2
, Jan-May,Dec
-- 关于如何执行此操作的任何建议?
read -a cron <<< "${cron_tab}"
if [[ "${cron[0]}" =~ ^(@(reboot|yearly|annualy|monthly|weekly|daily|hourly))$ ]]; then
...
#check minutes
if [[ "${cron[0]}" =~ ^([*]|[0-5][0-9]{1})$ ]]; then
...
#check hours
if [[ "${cron[1]}" =~ ^([*]|[01]?[0-9]|2[0-3])$ ]]; then
...
#check days
if [[ "${cron[2]}" =~ ^([*]|[0-2]?[0-9]|3[0-1])$ ]]; then
...
#check months
if [[ "${cron[3]}" =~ ^([*]|[0]?[0-9]|1[0-2])$ ]]; then
...
#check days of week
if [[ "${cron[4]}" =~ ^([*]|[0]?[0-7])$ ]]; then
...
Run Code Online (Sandbox Code Playgroud)