I have a python script that I've encapsulated in a bash function. I would like to be able to call this function as a cron job, but I cannot seem to get cron to execute it.
The function is as follows:
#!/bin/bash getmail(){ local interp=/path/python3 local cmd=/path/python-script local logfile=/path/logfile if [ "$1" == "-logs" ]; then $interp $cmd >> $logfile else $interp $cmd fi }
I've then created a script to source the function and execute it which I would like to be able to call from cron.
#!/bin/bash source /path/getmail getmail
I've assigned this cron-script appropiate permissions, making it executable, but cron won't run the script. I can run the python script itself via cron, but not encapsulated withn the bash function. I would just like to know why. Might it have something to do with the interpreter that cron is using? I've set the SHELL=/bin/bash in cron tab. Can anyone shed some light on this for me?
*/10 * * * * /bin/bash -c /full-path/scriptname.sh > /dev/null 2>&1
or simple way:*/10 * * * * /bin/bash -c /full-path/scriptname.sh
. If you did, there are many answers with a similar problem (how to run a Bash script via CRON)./usr/bin/python
(stackoverflow.com/questions/2589711/…). CRON example:*/10 * * * * /usr/bin/python /full_path/python_script.py
. Only importing modules can be a problem, but this can also be resolved by adding a suitable path to the python environments -sys.path.append("/path/to/python")
.#!/usr/bin/env python