Notes about cron tasks

Source: Internet
Author: User

1. crontab-E: edit the scheduled task. View crontab-L. The final cron task file is saved in the/var/spool/cron/crontab directory.

2. cron switches to the owner of the cron file in the/var/spool/cron/crontab directory and then runs the defined scheduled task.

3. When a Cron user is switched, no environment variables, including. bashrc, will be executed. Therefore, variables such as $ home are not defined. Therefore, in the script of the scheduled task, we will handle it like this:

#! /Bin/bash

Home =/home/markz

Source $ {home}/. bashrc

Export Path =/usr/local/bin: $ path

And then the specific task to be executed.

Note that ,~ /. Bashrc usually contains a lot of definitions and script execution, which may affect the successful execution of source. The reason why we add this source to the script that requires cron is to define some environment variables in most cases. So in order to ensure the success of source, we generally store the required environment variables in a file separately, and then go to the source file. Direct source ~ /. Bashrc is not a good practice.

4./var/log/syslog stores the cron log. You can view the log to conveniently know the execution status of the scheduled task.

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.