Schedule a Crontab

All,

I'm a newbie with crontab and I need your help with schedule a cold-backup running every Sunday at 7am except 1st of the month.
Thank you so much.

Read the 2 steps described bellow:

  1. To run on every Sunday at 7 a.m. you need something like:
    Month=* Day=* DayOfWeek=Sunday Hour=7am Minute=0 command
    which become
* * Sunday 7am 0 command
  1. You need to understand that the '10/11/12 7am' is a weird unreadable format for both people and computer (is it October, November or December?)
    Read about ISO-8601 about the notation
    For the crontab its date/time order is reversed in thus you get:
0 7 Sunday * * command

And the day is defined as a number - you need to verify this but I think that Sunday=7, thus the final code is:

0 7 7 * * command
  1. Probably you are most interested in filtering the "1st of the month".
$(date +%d) != '01'

You should use this as a conditional to your command:

[[ $(date +%d) != '01' ]] && backup_command
  1. Verify if this works and you might need to tune this for your OS, coreutils and shell

  2. Final entry in cron would look like:

0 7 7 * * [[ $(date +%d) != '01' ]] && backup_command
1 Like

here's our FAQ about cron and crontab, if you need