vi /etc/crontab 每填15点运行 这样写

89 阅读1分钟

在Linux系统中,/etc/crontab文件用于设置系统级别的cron作业。cron作业的格式如下:

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of the week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of the month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

如果你想设置一个cron作业,让它在每天的15点(即下午3点)运行,你可以按照以下格式来写:

0 15 * * * command-to-be-executed

这里的0 15 * * *表示:

  • 0 分钟(即小时的第0分钟)
  • 15 小时(即下午3点)
  • * 日期(每天)
  • * 月份(每个月)
  • * 星期几(每天)

command-to-be-executed是你希望执行的命令或脚本的路径。

请确保你有足够的权限来编辑/etc/crontab文件,通常需要root权限。编辑完成后,保存并退出编辑器,cron服务会自动重新加载配置文件,无需手动重启服务。