Crontab call shell script does not run

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.