Allowing user to configure cron
bash, cron, python
Solution
Give your users some reasonable choices like every minute, every 5 minutes, every half an hour, ... and translate these values to a cron job string. This is user friendly and forbids users to tamper directly with the cron job string.
Problem
I have this bash script on the server that runs every hour, via cron. I was perfectly happy, but now the user wants to be able to configure the frequency through the web interface. I don't feel comfortable manipulating the cron configuration programmatically, but I'm not sure if the other options are any better. The way I see it, I can either: - Schedule a script to run once a minute and check if it should really run "now" - Forgo cron altogether and use a deamon that is its own scheduler. This probably means rewriting the script in python - ...or suck it up and manipulate the cron configuration from the web interface (written in python BTW) What should I do? EDIT: to clarify, the main reason I'm apprehensive about manipulating cron is because it's basically text manipulation with no validation, and if I mess it up, none of my other cron jobs will run. Here's what I ended up doing: Taking stefanw's advice, I added the following line at the top of my bash script: ``` if [ ! `cat /home/username/settings/run.freq` = $1 ]; then exit 0 fi ``` I set up the following cron jobs: ``` 0 */2 * * * /home/username/scripts/publish.sh 2_hours @hourly /home/username/scripts/publish.sh 1_hour */30 * * * * /home/username/scripts/publish.sh 30_minutes */10 * * * * /home/username/scripts/publish.sh 10_minutes ``` From the web interface, I let the user choose between those four options, and based on what the user chose, I write the string `2_hours/1_hour/30_minutes/10_minutes` into the file at `/home/username/settings/run.freq`. I don't love it, but it seems like the best alternative.