1

I'm wanting schedule the execution python script at 08:00 AM, 18:00 PM and 22:00 PM. Checking the Crontab documentation, I think that the command would be

0 8,18,22 * * * /home/test/script.py

Now to create this task, Do I need to use crontab -e and last line add the command above?

1 Answers1

1

Looks correct to me.

Yes, you can open the task list by use of crontab -e. But you need to make sure, permissions are correct. If the script needs root access, you can't run it as user.

Also, just editing the task list alone won't do the trick. You need to make sure, some daemon like cronie is active and running to execute the tasks.

You can check, if cronie is active by use of:

systemctl status cronie

It might ask for permission or you might have to use sudo.

3 possible outcomes. Cronie might be active, inactive or not even installed. Last one should be fairly self-explanatory. You need to install cronie (apt-get install cronie).

systemctl start cronie.service

would start it temporarily. Usually that works fine and needs no settings. You can check the status again.

To make sure it's active after reboot and always, you need to ...

systemctl enable cronie.service

Just to have mentioned it, as a helper: if you are not sure about anything about this, you can always use some dummy script for testing. Just let it for example echo a timestamp into a file and see if it works.

Neobie
  • 151
  • Should put python before the path, right? 0 8,18,22 * * * python /home/test/script.py – Shinomoto Asakura Jun 20 '18 at 22:46
  • Not necessarily. You need to make sure the script is executable (chmod +x /home/test/script.py). And if you use the #! (spoken hash-bang) at the beginning of the script, you don't need the python command at the beginning ;) Depends on the version you are using. But if you use default ... I think that should be some 3 like 3.6 or so, #!/usr/bin/env python at the beginning of the script will do ;) – Neobie Jun 20 '18 at 22:48
  • AFAIK Debian and its derivatives use Vixie cron, and it should be installed / enabled by default (verify with systemctl status cron.service) - I can't even see cronie in the default repos. Did I miss something? – steeldriver Jun 20 '18 at 23:36
  • This one might be on me. Primiarily I'm using Arch these day and I'm used to cronie. On the other hand, quickly switching device and performing an apt-cache search, I find neither cronie nor vixie. Is it possible you are using something else than Desktop, like server or something? That might explain a lot. I'm getting systemd-cron, mcron and bcron in Ubuntu. But the process should be basically the same. – Neobie Jun 20 '18 at 23:57
  • Just use your best judgement and as mentioned before, if in doubt you can always run a test script ;) – Neobie Jun 20 '18 at 23:58