I want something to run at three minutes past midnight, and at 7am. Is there a cron…
- User
I want something to run at three minutes past midnight, and at 7am. Is there a cron pattern for that
Assistant
A cron question! Yes, I can help you with that.
Cron patterns are a great way to schedule tasks, and they're quite flexible. Here's the cron pattern you're looking for:
3 0 * * * # runs at 00:03 (3 minutes past midnight) 0 7 * * * # runs at 07:00 (7am)Let's break down the format:
minute hour day month day_of_week commandminute: 0-59hour: 0-23 (0 = midnight, 1 = 1am, ..., 23 = 11pm)day: 1-31 (day of the month)month: 1-12 (or JAN-DEC)day_of_week: 0-6 (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
Now, let's analyze the two patterns:
3 0 * * *3: minute 30: hour 0 (midnight)*: any day of the month*: any month*: any day of the week => Runs at 00:03 (3 minutes past midnight) every day.
0 7 * * *0: minute 07: hour 7 (7am)*: any day of the month*: any month*: any day of the week => Runs at 07:00 (7am) every day.
You can combine these two lines into a single crontab entry (e.g., in
/etc/crontabor usingcrontab -e):3 0 * * * your_command_here 0 7 * * * your_command_hereReplace
your_command_herewith the actual command or script you want to run at these times.Tips:
- If you want to run the same command at both times, you can use a single line with multiple times:
3 0,7 * * * your_command_here. However, this won't work here, since0,7would mean "hour 0 and hour 7, minute 3" (i.e., 00:03 and 07:03), not what we want. - To verify your cron patterns, use Crontab.guru, a fantastic online tool that explains and validates cron expressions.
- Don't forget to set the correct timezone! By default, cron uses the system timezone. If you need a different timezone, you might need to set the
TZenvironment variable or use a wrapper script.
Happy scheduling!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.