First thing make sure that cron
is installed:
which cron
If it's not the case simply install it by executing the following command:
sudo apt-get install cron
* * * * * command_to_be_executed
| | | | |
| | | | +----- Day of the Week (0 - 6) (Sunday = 0)
| | | +------- Month (1 - 12)
| | +--------- Day of the Month (1 - 31)
| +----------- Hour (0 - 23)
+------------- Minute (0 - 59)
Let's assume we want to run a python
script each minute, we have to run the following command to edit the crontab
:
crontab -e
then add a new line representing the shell command to run, in our case it would be:
*/1 * * * * python /path_to_script/script.py
You can use https://crontab.guru to get the right cron to be used.
You can then show the list of crons using
crontab -l
python
, you can use python-crontab