Crontab the reason that the shell script failed to execute at timed time

Source: Internet
Author: User

There is a period of time without crontab scheduled to perform tasks, this time to take advantage of the project implementation of the opportunity to further analyze the Crontab timing task settings encountered some difficult problems.

Crontab-l View the crontab information that is currently set

CRONTAB-E Editing timed tasks

Examples Show

*/1 * * * * jstack process number >> Jstack.log

The first five "*" numbers represent "minutes (0-59) hours (0-23) days (1-31) months (1-12) weeks (0-6, 0 means Sunday)

In the example above, the jstack is executed every other minute and the result of the operation is output to Jstack.log.

A small partner may say that such execution may not succeed Oh, then the question came, why not succeed?

If you are currently using the root user, and if the environment variables are configured with the Java environment variables, then it is no problem to execute the above crontab, but if you use other new users, although you may also have configured the Java environment variables

However, Crontab does not read the contents of your other user environment variables, so the solution is to save the execution command as a shell script, display the environment variables executing the current user in the script, and then run the command output

1 # !/bin/bash 2 . /etc/profile3 . ~/. Bash_profile4echo get Java process number 5$"6  ${pid}7Echo starts recording jstack information and outputs Jstack.log8${pid} to the root directory >> Jstack.log

Let's say the above code is saved to the jstack.sh file so that when the crontab is set, it is directly

*/1 * * * */home/test/jstack.sh

This will allow you to observe the growth of the Jstack.log file, thus avoiding the problem of using absolute paths.

Crontab the reason that the shell script failed to execute at timed time

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.