although crontab is able to schedule intervals (i.e.
*/2 * * * * command.sh for every 2 minutes), it is not able to schedule every 3 weeks. the solution is to add some calculations (using day of year and modulo) to the script itself:
#!/bin/bash # this script will execute a command every n weeks # usage: it should be started using cron or runwhen once a week # found at: https://nerd.one/solved-execute-cronjob-every-3-weeks # set interval (in weeks) INTERVAL=3 # get week of year WEEK=$(/bin/date +%V) # run command if WEEK is divisible by INTERVAL if [ $(( $WEEK % $INTERVAL )) -eq 0 ]; then # WEEK is divisible by INTERVAL # execute command ... echo $WEEK fi
yes, you'll say: that does not work properly at the turn of a year--but maybe this is okay in your use case.