Start a Cron job twice a week or the first wednesday every month or every year on 1st sunday

Start a Cron job twice a week or the first wednesday every month or every vear on 1st sunday!
[EDIT] At first I used MON, TUE, THU and so on,maybe that was part of the problem? But I did not try it out so far…
My config:

  1 # Please use dietpi-cron to change cron start times
  2 SHELL=/bin/dash
  3 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  4 MAILTO=""
  5
  6 # m h dom mon dow user command
  7 #*/0 * * * * root cd / && run-parts --report /etc/cron.minutely
  8 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  9 35 19 * * 1,4 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
 10 18 19 * * 6 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
 11 30 7 * * 7 root [ $(date +\%d) -le 07 ] && (test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; })

BTW, dietpi-cron changed my crontab!! Before I wanted to do cron jobs without dietpi-cron but it failed to start though I restarted cron by

service cron restart 

This is config of dietpi-cron:

/e/crontab                                                                                                                                                                                                                                                                                   1 # Please use dietpi-cron to change cron start times
  2 SHELL=/bin/dash                                                                                                                                                                                                                                                                           3 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  4 MAILTO=""
  5
  6 # m h dom mon dow user command
  7 #*/0 * * * * root cd / && run-parts --report /etc/cron.minutely
  8 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  9 25 1 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
 10 18 23 * * 4 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
 11 30 7 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; }
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             /etc/crontab   CWD: /root   Line: 9

Since i used dietpi-cron it starts at least… The crontab above is what I have restored

My idea is, how does dietpi-cron and /etc/crontab interact here? How can I run my crontab here?
I need this respecially for my ssd snapshots which take a long time to finish (up to half a day).

And off topic😎: is it possible to schedule a cron job every on 1st sunday? I guess it would be similar like in line 11 of my first script. Or a script to check the conditions…

dietpi-cron is used to change the time/day that cronjobs run and add some MailTo info.
The script can be saved inside the respective /etc/cron.*/ directory for hourly,daily,weekly,monthly usage or edited directly with crontab -e

I didn’t find any built in way, so you’ll have to check the conditions. Better NOT edit the file directly, or dietpi-cron will overwrite your changes. Better use crontab -e for this customization.

1 Like

yes, you would need to use crontab -e if you like to adjust/edit the user crontab.

yes this is possible. You could have used one of your favorite search engines to answer the question yourself. bash - How to schedule to run first Sunday of every month - Stack Overflow

Following crontab entry should do

00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script