Configuration·Python Automation for IT
Python Scripts with cron and systemd Timers
"It works when I run it and not from cron" is almost always the environment. This guide runs one script three ways and counts what it gets: **16** environment variables interactively, **6** under cron, **22** under systemd - and shows cron using your home directory as the working directory while systemd honours `WorkingDirectory=`. Then the part cron cannot do: a recorded failure you can query afterwards.
OS and Process Automation Guide 23 of 39 Intermediate
- Python3.14.4
- Control nodeUbuntu 26.04 LTS
- Managed hostsRHEL 10.0
- requests2.34.2
- paramiko5.0.0
- pytest9.1.1
- PyYAML6.0.3
- boto3 / botocore1.43.78
- TimeAbout 20 min
- Reviewed24 August 2026
Written against the versions above. systemd user timers need a logged-in session or `loginctl enable-linger`. `OnUnitActiveSec` and `Persistent=` are long-standing options; `systemd-analyze verify` will check a unit before you install it.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Control node - every script in this path runs here | 2 Core | 4 GB | 50 GB |
Before you start
- guide 9 - the same problem from the script's side.
- guide 22 - which a scheduled job needs.
- guide 8 - the interpreter path both use.
-
One script, run three ways
-
A crontab entry, in full
-
What cron gave it
-
The same job as a systemd timer
-
Start it, and what systemd gave it
-
What the journal recorded
-
A failing run, and what systemd says about it
-
The whole comparison, in one file