I need to set up a weekly email that cycles between 4 variations, eg.
- variation a
- then b
- then c
- then d
- then back to a
- etc
each week.
I’d like to do this using 4 cron tasks (each of which sends an email every 4 weeks), but I’m having trouble staggering them so that each task starts on a different week, rather than having them all send their emails on the first week then having nothing for the next 4 weeks.
My crontab looks like this at the moment:
0 8 * * 1/4 echo "Variation A" | mail -s "Test email" admin@mydomain.com
0 8 * * 1/4 echo "Variation B" | mail -s "Test email" admin@mydomain.com
0 8 * * 1/4 echo "Variation C" | mail -s "Test email" admin@mydomain.com
0 8 * * 1/4 echo "Variation D" | mail -s "Test email" admin@mydomain.com
I feel a bit like if I could control when each one sends the email for the first time then I could get it working right?
Can anyone see a better way of doing this? Preferably with a minimal of scripting (I’d like to keep all of the details within the crontab)
This is not something you can do with cron alone. You will have to use some sort of script to do this, storing the last variation you sent, and deciding which to send next based on that info. The cron entry would look something like:
This will execute the script at 8AM every Sunday. The script itself will have to decide which message to send.
You could use something like this: