How To Schedule Python Scripts As Cron Jobs With Crontab (Mac/Linux) - Python Task Automation



In this tutorial, we learn about cron jobs and how to schedule commands and Python scripts in the terminal via crontab (for Linux and Mac). This allows us to run commands on a repetitive schedule. We specifically look into running Python scripts as cron jobs. There are a couple of pitfalls where we have to be careful. We also learn how to schedule jobs with a virtual environment.

✅ Write cleaner code with Sourcery, instant refactoring suggestions in VS Code & PyCharm: https://sourcery.ai/?utm_source=youtube&utm_campaign=pythonengineer *

⭐ Join Our Discord : https://discord.gg/FHMg9tKFSN

🚀🚀 Get monthly Python and ML Tips:
https://www.python-engineer.com/newsletter/

🚀🚀 SUPPORT ME ON PATREON:
https://www.patreon.com/patrickloeber

If you enjoyed this video, please subscribe to the channel!

Timeline:
00:00 – Introduction
01:20 – Cron syntax
06:00 – Crontab
07:15 – Python scripts
10:40 – Virtual Environment

Code:
https://github.com/python-engineer/python-task-automation

You can find me here:
Website: https://www.python-engineer.com
Twitter: https://twitter.com/python_engineer
GitHub: https://github.com/python-engineer

Music: https://www.bensound.com/

Photo by Kari Shea: https://unsplash.com/photos/1SAnrIxw5OY

#Python

———————————————————————————————————-
* This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏

source

26 thoughts on “How To Schedule Python Scripts As Cron Jobs With Crontab (Mac/Linux) – Python Task Automation”
  1. Hello sir,How can configure crontab to run a script

    Second saturday will be execute at 5 AM

    and other all saturday will be execute at 5 PM

    Please help me sir

    Thanks in advance

  2. Mac users need to add full disk access for cron process if ur handling files in the python scrits

  3. How to run a crontab every 2 weeks on the same day of the week? e.g Sun Feb 6th , Feb 20th , March 6th

  4. I really like how you starting with the basics and built up over the course of the video. I never comment on YouTube videos but this one was really helpful. Thanks.

  5. I apologize if I offend you, I like legacy tech too. Old but well tested (also by the long-term of succesful usage) and fine working programs sometimes much better choise. But systemd were released in 2010 – 11 years ago, with easy to use sintax, supporting task chaining, flexyble limiting resourses, streaming task states, templating. And you talk about CRON? Really? In 2021?

  6. An easy-to-follow and easy-to-understand tutorial. Helped me a lot. Thanks for the effort.

  7. really nice delivery, pretty clear and easy to follow, however it just doesn't seem to work for me, I've searched all over but can't can't find why . I don't get any error, the log just doesn't get updated, even though the Cron Job seems to be registered

  8. This is brilliant! Exactly what I was looking for – to run a specific script everyday at a certain time. Thank You!!!

  9. Thanks dude. I’m sure the next video is about Airflow.Yesterday I was wondering. Are you actually an ML engineer in a company or do you make a living out in of YouTube videos ?

Leave a Reply

Your email address will not be published.

Captcha loading...