Skip to content

Scheduling Scripts on Linux/Mac (Cron Jobs)

Cron basics

Cron runs commands on a schedule.

Common gotchas:

  • minimal PATH
  • different working directory

Pattern

  • use absolute paths
  • redirect outputs

Example crontab entry:

text
0 9 * * * /usr/bin/python3 /home/user/job.py >> /home/user/job.log 2>&1
text
0 9 * * * /usr/bin/python3 /home/user/job.py >> /home/user/job.log 2>&1

Tip

Use logging in the script, not only stdout.

🧪 Try It Yourself

Exercise 1 – List Files with os.listdir

Exercise 2 – Join Paths with os.path.join

Exercise 3 – Write and Read a File

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did