You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Crontab周四定时任务异常求助:配置周四23:55执行重启脚本却在周一或周二触发

Fixing Your Thursday-Only Crontab Restart Task

Hey there, let's get this sorted out quickly—your current crontab entry is running every single day at 11:55 PM, which explains why it's triggering on Mondays/Tuesdays instead of only Thursdays.

The Root Cause

Crontab follows a 5-field schedule structure (plus the command to run):

分钟 小时 日 月 星期几 命令

Your existing entry 55 23 * * * /usr/html/scheduler/restart.sh > /usr/html/scheduler/file.log uses a * in the 5th field (day of week), which translates to "every day". That's why it's firing daily instead of just your intended Thursdays.

The Correct Crontab Entry

To restrict the task to only Thursdays, set the 5th field to 4 (note: in most crontab implementations, 0=Sunday, 1=Monday, ..., 4=Thursday, 7=Sunday). Here's the fixed line:

55 23 * * 4 /usr/html/scheduler/restart.sh >> /usr/html/scheduler/file.log 2>&1

I added two small but useful tweaks:

  • Changed > to >> to append log entries instead of overwriting the file each time (so you can keep a full history of runs)
  • Added 2>&1 to capture both standard output and error messages in the log—this makes it way easier to debug if the script fails silently

Additional Troubleshooting Steps

If you still hit issues after updating the entry:

  • Confirm the crontab was saved properly with crontab -l (this lists all your scheduled tasks)
  • Check system cron logs (usually at /var/log/cron or /var/log/syslog) to verify the task is being triggered on Thursdays
  • Ensure your script has execute permissions: run chmod +x /usr/html/scheduler/restart.sh
  • Test the script manually first to confirm it works as expected: /usr/html/scheduler/restart.sh

内容的提问来源于stack exchange,提问作者Elaine Byene

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 16:22:39