[Shell] crontab executes the task and calls the shell script. The relative path cannot be found. crontabshell

Source: Internet
Author: User

[Shell] crontab executes the task and calls the shell script. The relative path cannot be found. crontabshell

The scenario where the problem occurs is probably


1 cron calls a python script

2. In the python script, call a shell script (for log analysis) to obtain the shell output and then send an email.

Similar to a monitoring task.


There is no problem in directly executing the python script, but after writing it in cron, the relative path in the shell script cannot be found, and it always prompts that some files cannot be found.

The problem solved later was to use the absolute path of the log file and the operation would be normal.


Google has found that many people have encountered similar problems, which may be related to the cron mechanism.


Most people's problems are caused by environment variables, because cron is an independent process, not a user login, and so on, so some programs cannot be executed successfully.

Similar: http://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths


However, many scripts are basically absolute paths, and I may write too little. Many principles and principles are not very clear.


This article is from the "orangleliu notebook" blog, please be sure to keep this http://blog.csdn.net/orangleliu/article/details/38641417



Shell script is not executed in the scheduled task. The simple SH is used to compress the crontab of the log yesterday. It is defined to be executed at half past four every day, but it is not executed.

See where bzip2 is in the system, for example, in/usr/bin.

Replace bzip2-9 *. log

Cd/data/$ {y}/$ {m}/$ {d}

/Usr/bin/bzip2-9 *. log

Try it.

Crontab does not execute shell scripts

You may not find your java command in the cron environment.
You can import environment variables in your script.

Related Article

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.