Crontab reasons for not performing scheduled tasks and viewing task execution

Source: Internet
Author: User

There must be a lot of people like me, have encountered in the local call script, can execute normally, but after writing the crontab timed task, there will be a part of the execution, part of the problem is not executed. Or the same script, the same scheduled task, but on some servers can be executed, some are not.

After reviewing the relevant data, crontab always does not read the environment variable from the user profile file by default, that is, the problem of environment variable, or the path problem. The solution is as follows:

1. Use absolute path for command;

2, the script at the beginning of the call to add the following, in order to read the user's environment variable parameters, solve the problem of environment variables; Example: #! /bin/bash

. /etc/profile

. ~/.bash_profile

3, you can also add the following how to easily view the execution of the script;

Example: * * * * * * echo|/tmp/test.sh >>/tmp/test/txt

4. You can check whether the task is performed by Tail-f/var/log/cron.

This article is from the "11366164" blog, please be sure to keep this source http://11376164.blog.51cto.com/11366164/1790848

Crontab reasons for not performing scheduled tasks and viewing task execution

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.