Scheduled Tasks in Linux crontab

Source: Internet
Author: User

What you will encounter at work
    • A program needs to be executed every minute to check the system running status

    • Daily Lincheng need to count business data for the past day

    • Log files need to be backed up every week

    • Need to back up the database every month

Crontab is

A tool for setting up tasks that are periodically executed.

Crontab app installs and checks crontab services

Check that the Crontab tool is installed and that there is no error indicating that it is installed correctly

-l

Check the status of the Crond service

service crond status
The basic composition of crontab

There are three components:

    1. Configuration files: Set up Scheduled tasks as a file

    2. System Services (Crond): Refreshes the scheduled task from the configuration file every minute

    3. Configuration Tool (Crontab): For adjusting timed tasks

Configuration file format for crontab
    • Use the CRONTAB-E command to open and edit (Default user) task profiles.

    • Format of the scheduled task file

          \* \* \* \* \* command 分 时 日 月 周 命令
Example:
  • 21:30 restarts Apache per night

    30 21 * * * service httpd restart
  • 1, 10, 22nd of 4:45 restart Apache

    45 4 1,10,22 * * service httpd restart
  • 4:45 restart Apache for 1-10 days per month

    45 4 1-10 * * service httpd restart
  • Restart Apache server every two minutes

    */2 * * * * service httpd restart      1-59/2 * * * * service httpd restart
  • Between 11 o'clock and 7 in the morning, restart Apache every hour.

    0 23-7/1 * * * service httpd restart
  • Restart Apache every 30 minutes from 18:00 to 23:00 every day

    0,30 18-23 * * * service httpd restart0-59/30 18-23 * * * service httpd restart
Use of crontab Tools
    • View the crontab command

      crontab -help 
    • Create User crontab command

      -e -u user_name
    • Viewing user actions for User name user_name

      -l -u crontester
    • View Log file

      -f /var/log/cron
Configuration file for Crontab
    • The file/etc/crontab is a global (System) configuration file for crontab, or you can set up system scheduled tasks in the file.
      + File/etc/cron.d/sysstat This is a scheduled task that comes with the system, and when crontab loads the configuration file, it loads the configuration information for the CRON.D below into the scheduled task of being the root user.

You can edit the/etc/cron.d/sysstat add task after you execute crontab sysstat import file to make it effective.

    • Each user has a separate file directory, file location:/var/spool/cron

Crontab's Log
    • Log Address:/var/log/cron


Scheduled Tasks in Linux crontab

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.