linux定时执行

时间:2024-04-30 04:33:05
/root/crontab-conf文件为root用户定时执行计划文件
 命令:crontab -l
说明:列出定时执行的计划列表
命令:crontab -e
说明:编辑定时执行的计划文件

每五分钟执行  */5 * * * *

每小时执行     0 * * * *

每天执行        0 0 * * *

每周执行       0 0 * * 0

每月执行        0 0 1 * *

每年执行       0 0 1 1 *

执行结果输出到文件,默认所在目录为crontab-conf

crontabl 的日志/var/log/cron

===========================================================

*/1 * * * * /Tomcat/apache-tomcat-7.0.34/bin/test.sh

每分钟把时间写到文件中

#!/bin/sh

echo $(date "+%Y-%m-%d %H:%M:%S") >> "min.log"

============================================================

1 0 1 * * /Tomcat/apache-tomcat-7.0.34/bin/delete-log.sh

每个月删除文件,并把日期写到文件中

#!/bin/sh

last_month=$(date -d last-month +%Y-%m)

log_files="/Tomcat/apache-tomcat-7.0.34/logs/*${last_month}*.log"

echo ${last_month} >> "delete.log"

`rm -f ${log_files}`