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