Running a Python Script with Arguments in Cron
Put the arguments after the script path just like on the command line, using the full interpreter and script paths. Watch two traps: cron's minimal PATH and the % character, which cron treats as a newline unless you escape it as \%.
The crontab line
0 2 * * * /usr/bin/python3 /opt/app/run.py --mode daily --limit 100 >> /var/log/run.log 2>&1
Arguments follow the script path exactly as in a shell. Use the venv python (/opt/app/venv/bin/python) if the script needs venv packages.
Escape percent signs
If an argument contains % (like a date format), escape it: --date $(date +\%Y-\%m-\%d). Unescaped % becomes a newline and breaks the job.
Quote arguments with spaces
0 2 * * * /usr/bin/python3 /opt/app/run.py --name "nightly report" — quote any value containing spaces so it stays one argument.
FAQ
How do I pass arguments to a Python script in cron?
Place them after the script path: 0 2 * * * /usr/bin/python3 /opt/app/run.py --mode daily --limit 100. Same syntax as the shell.
Why does % break my cron python arguments?
Cron reads % as a newline. Escape it as \% inside arguments, e.g. date +\%Y-\%m-\%d, or the job fails.
How do I pass an argument with spaces to cron?
Wrap it in double quotes: --name "nightly report", so cron passes it as a single argument.