首先crontab不是Linux内核的功能,而是依赖一个crond服务,这个服务可以启动当然也可以停止。如果停止了就无法执行任何定时任务了,解决的方法是打开它。打开方法:service crond start
其次crontab中,执行脚本需要传入系统时间$(date +"%Y%m%d%H"),配置后一直无法正常调度,后来发现是%的原因,需要转义,正确配置为:
$(date +"\%Y\%m\%d\%H")
原因: linux man 英文文档介绍:Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
即 ‘%’ 对于conrtab来说具有特殊含义,遇到%相当于换行符,如果参数中含有该类参数 要用 ‘\’进行转义。