linux添加定时任务(crontab)

版权声明:本文为博主原创文章,未经博主允许不得转载。如需转载,加上原文链接即可~~ https://blog.csdn.net/hpulfc/article/details/86607000

crontab

在linux上做定时任务,定时的去执行一些操作。
一般是安装,并且启动服务(略)

查看定时任务:

crontab -l

0 0 1 * * /home/kratos/local/bin/python /home/kratos/src/furion_current/furion/script/order_statistic/clear_expired_orders.py

添加定时任务

crontab -e
一般写法是前面指定时间,后面是定时的命令。

时间的格式是:有5段,分别表示分钟、小时、天、月、周
例如:

  • 1 1 * * * 表示每天1点1分 执行
  • 0 0 * * 0 表示每周0点0分 执行

使用*表示每分钟,每小时,每天

详细格式

# 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

查看定时任务是否执行

直接查看日志

一般任务日志位于 /var/log/cron

cat /var/log/cron

Jan 23 04:01:01 iZwz9g2hqiikgrid28nvxnZ CROND[5795]: (root) CMD (run-parts /etc/cron.hourly)
Jan 23 04:01:01 iZwz9g2hqiikgrid28nvxnZ CROND[5796]: (kratos) CMD (/home/kratos/local/bin/python /home/kratos/src/furion_current/furion/script/order_statistic/sync_update_order.py)
Jan 23 04:01:01 iZwz9g2hqiikgrid28nvxnZ run-parts(/etc/cron.hourly)[5795]: starting 0anacron
Jan 23 04:01:01 iZwz9g2hqiikgrid28nvxnZ run-parts(/etc/cron.hourly)[5805]: finished 0anacron
Jan 23 04:01:01 iZwz9g2hqiikgrid28nvxnZ CROND[5794]: (kratos) MAIL (mailed 169 bytes of output but got status 0x0001#012)

上面kratos的cmd 表示在4点1分1秒 执行了命令

猜你喜欢

转载自blog.csdn.net/hpulfc/article/details/86607000
今日推荐