Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Source Link
queuedq
  • 33
  • 1
  • 1
  • 3

How do I add/remove cron jobs by script?

I'm going to make a bash script that is executed at boot and runs periodically.

I want it user-configurable, so that a user can add a cron job 0 * * * * my_script by running my_script add 0 * * * *, list jobs by my_script list, and remove by my_script remove job_number where the job number is listed in the output of my_script list command.

If I could manage crontab files separately, this would be easily achieved. However, It seems crontab is only one file per a user (If not, please let me know). Directly dealing with that crontab file is a bad solution, of course.

So what is the proper way to handle the cron jobs? Or, is there a better way to handle periodically running scripts?

Conditions:

  1. Any user should be able to run it, whether privileged or not.
  2. No dependencies.

Additional question:

Since I couldn't find any proper way to manage periodically running scripts, I thought what I might be doing wrong. In the sense of software design, is it not practical to implement the interface to manage the software's scheduled tasks? Should I leave all schedule managements to users?