How to Schedule a Python Script Cron Job

My script

from datetime import datetimeprint(datetime.now())

Cron Jobs and Virtual Environments

Set-up the Cron Job

crontab -e 
sudo crontab -e 

File Paths

* * * * * /usr/bin/python3 /home/gavin/python-job.py >> ~/cron.log 2>&1
* * * * * $(which python3) /home/gavin/python-job.py >> ~/cron.log 2>&1
* * * * * cd /home/gavin && $(which python3) python-job.py >> ~/cron.log 2>&1

Alternative Approach: Executable Python Script

chmod +x <python file>
* * * * * /home/gavin/python-job.py >> ~/cron.log 2>&1

--

--

--

I'm a coder and freelancer from South Africa with 5+ years experience in automations, integrations and API's using Python and Django.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Agile — The Developer’s Mentality

NVIDIA Jetson Nano, a Raspberry Pi on steroids

unboxed

Go: Using Uber Zap in your Application

What’s the Difference Between Manual and Automation Testing?

HireTester. Difference between manual and automation testing

How to configure AWS S3 bucket to store customer data

[Django] AWS EC2에 서버 배포하기(2)

Notice: DeployGate Ending New Personal Pro Plan Subscriptions

START CARING STOP SHARING

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gavin Wiener

Gavin Wiener

I'm a coder and freelancer from South Africa with 5+ years experience in automations, integrations and API's using Python and Django.

More from Medium

Creating a Book Class 📚

[Day 2/100 Python Project]

How to start learning web development with Python (Flask edition)

Getting Started in Coding with Python for Beginners (Step 1)