Menu

Cron Expression for Every Day at Midnight (0 0 * * *)
πŸ“°

Cron Expression for Every Day at Midnight (0 0 * * *)

DEV Community: githubΒ·lifeissoupΒ·3 days ago
#RZGdcGXd
#devtogithub#technology#devto#dev#midnight
Reading 0:00
15s threshold

To run a cron job every day at midnight, use 0 0 * * * . That means minute 0, hour 0, every day of the month, every month, every day of the week. If you want to check a variation before deploying it, the Cron Expression Generator explains any 5-field expression in plain English and previews the next run times.

The midnight expression, field by field

0 0 * * * | | | | | | | | | +-- day of week (0-7, Sunday is 0 or 7) | | | +---- month (1-12) | | +------ day of month (1-31) | +-------- hour (0-23) +---------- minute (0-59)

Enter fullscreen mode

Exit fullscreen mode

Hours use a 24-hour clock, so midnight is hour 0 , not 12 and not 24 . A full crontab line looks like this:

0 0 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2 >& 1

Enter fullscreen mode

Exit fullscreen mode

Edit your crontab with crontab -e . The >> ... 2>&1 part appends both stdout and stderr to a log file.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.