The ampersand (for sending a process in the background) is not necessary for commands issued to cron via the crontab as processes are already forked. The given examples work fine without the &
. Actually the first version shows working parameters as it invokes the python interpreter with the filename of the script to be executed as parameter.
0,30 * * * * python /home/pi/pythonscripts/script.py foobar
or
0,30 * * * * /home/pi/pythonscripts/script.py foobar
where script.py
contains the first line #!/bin/python3
and has executable flags.
An example how to use and print the passed parameter (per question of the OP):
import sys
for arg in sys.argv:
print(arg)
Parsing through the list argv
that contains the parameters passed to the script. argv[0]
contains the name (and path) of the script. argv[1]
is the first parameter, and so on. For more serious handling of arguments it is advisable to use argparse
(tutorial) instead of reinventing the wheel.