I am working on a small home automation project using raspberry pi (OS -Raspbian).

I want to know how to add more than one crontab file using python-crontab module without replacing the previous entries in crontab -e?

I want to programatically (without manually going to crontab -e and adding the files there) schedule two python scripts - first script executes after every 5 minute and another executes after every 2 min.

I was successfully able to schedule first script using python-crontab module but when I scheduled second script, it replaced the first one in crontab -e. So how to schedule the new crontab file without replacing the previous one ?

If there is another way of crontab scheduling please do suggest with an example code :)

Note:- I want to schedule python scripts in crontab using python scripting only not manually adding the files at crontab -e.


If you want to write a script to add entries in cron (without using the text editor via crontab -e), it would be something like:

  • run crontab -l to a temporary file
  • check if your latest command is already in the file. If so, stop.
  • append the latest command to the temporary file
  • run crontab with the temporary file as a parameter, to replace the scheduled commands

For reference:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.