A shell script was recently invoked with Crontab, and a Python script was invoked inside the shell script
In fact, it is to abandon Python to write a judgment trouble, using the shell to write a if to judge the case to run this Python script.
But after the deployment of direct SH test.sh script run no problem, but put in crontab in the dead or alive is not running in this record reason
Cause one: The shell script calls a command IP addr |egrep in this case, the IP reputation is under/sbin, but the crontab called environment variable directory is/bin so the runtime fails when invoking the shell script in crontab
Workaround: See if the command called in the shell script has a default environment variable directory that is not in the/bin command, and then modifies the absolute path in the script
Reason two: The syntax in the shell script is wrong, this direct sh-x yourself debugging it
Reason three: The Python script does not indicate an environment variable at the beginning. So the run failed in the shell script
Workaround: Add in the py script
#!/usr/bin/env python
In addition, when deploying this script, the development script colleague writes the annotation the Chinese, but the wonderful thing is, he unexpectedly did not have the Chinese code in the script to indicate. Causes an error when running the script. The same database also accepts no data. So, Pro: If you have a Chinese or Chinese comment in your Python script, make sure you remember to add
#-*-Coding:utf-8-*-
Mark this code.
Crontab call shell script does not run