crontab 定时任务的坑(无法执行定时任务)

业务需求新增一条定时任务,部署之后发现没有定时执行?

/bin/bash escho 2 2>> /root/"$(date +%Y%m%d)".log
# 错误的日志
(root) CMD (/bin/bash escho 2 2>> /root/"$(/bin/bash date +)

查了一下资料是因为%,在crontab里是换行的意思,需要进行转义 \%

/bin/bash escho 2 2>> /root/"$(date +\%Y\%m\%d)".log
# 正确的日志
(root) CMD (/bin/bash escho 2 2>> /root/"$(date +%Y%m%d)".log)
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

这些都是运维经验!

posted @ 2020-09-03 15:26  运维之爪  阅读(549)  评论(0编辑  收藏  举报