crontab -e 配置定时任务

  • Post author:
  • Post category:其他




时间格式

在这里插入图片描述




crontab -e

具体配置

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m       h       dom    mon  dow    command
# 分钟    小时     某天    某月  星期几  命令

0 23 * * * /root/scripts/login_day.sh
0 23 * * 7 /root/scripts/login_week.sh
0 0 1 * *  /root/scripts/login_month.sh

# total used time(hours) of every province for everyday
0 23 * * * /root/scripts/day_total_used_time.sh





examples

Every Minute
* * * * *
Every Five Minutes
*/5 * * * *
Every 10 Minutes
*/10 * * * *
Every 15 Minutes
*/15 * * * *
Every 30 Minutes
*/30 * * * *
Every Hour
0 * * * *
Every Two Hours
0 */2 * * *
Every Six Hours
0 */6 * * *
Every 12 Hours
0 */12 * * *
During the Work Day
*/5 9-17 * * *
Every day at Midnight
0 0 * * *
Every Two Weeks
0 0 * * Sun [ $(expr $(date +%W) % 2) -eq 1 ] && /path/to/command
At the Start of Every Month
0 0 1 * *
On January 1st at Midnight
0 0 1 1 *



References


  1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07

  2. https://crontab.guru/examples.html



版权声明:本文为power_to_go原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。