一 在 crontab中的date命令
概述
在crontab 中使用 date命令行 正确做法:
crontab -e * * * * * touch file_`date +\%Y-\%m-\%d_-\%H:\%M:\%S`.sql
上述含义
编辑crontab 定时任务:每分钟在用户端根目录下创建一个如下格式的文件
file_2012-11-08_-12:16:01
要点
%在crontab中被认为是newline,要用\来转义才行。比如crontab执行行中,如果有‘date +%Y%m%d‘,必须替换为:‘date +\%Y\%m\%d‘
二 在 crontab中执行shell文件
概述
在crontab 中执行shell脚本文件 需要添加sh命令
例如
crontab -e
* * * * * sh /var/lib/mysql/doc/backupcici.sh
三 查看crontab 详细信息解释
[root@localhost etc]# vi /etc/crontab
# 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