I have a python script that accepts custom parameters via sys and getopt modules. The cron job looks like:
* * * * * /HS/py/py_venv/venv/bin/python /HS/py/py_venv/src/SP/yh_scrape_product_info.py -c TSX.AP% -vpn False
I have narrowed down this problem to the first argument TSX.AP%.
This is a parameter that I take to execute a DB query.
If I add the wildcard % inside my script, therefore only passing TSX.AP to cron, the crojob works. This also works if i paste the command directly inside the terminal like this:
/HS/py/py_venv/venv/bin/python /HS/py/py_venv/src/SP/yh_scrape_product_info.py -c TSX.AP% -vpn False
Now I am thinking to add another argument to specify wether the wildcard needs to be added or not, but I would like to understand if there is a better solution and also this problem made me lose almost the whole day troubleshooting I really want to understand what it happening!
Thanks in advance!
Advertisement
Answer
From man 5 crontab
:
The ``sixth'' field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characā ters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "".
In particular: Percent-signs (%) in the command, unless escaped with backslash (),
A simple work-around would be to put /HS/py/py_venv/venv/bin/python /HS/py/py_venv/src/SP/yh_scrape_product_info.py -c TSX.AP% -vpn False
in a bash script and run that from cron.