How to use crontab under CentOS 5.5

Source: Internet
Author: User
Tags command line php file requires centos linux

Server System: 64Bit CentOS 5.5

Although the introduction of Crontab is everywhere, read the term in detail, the harvest is still available. Crontab This name comes from "Chronos", an ancient Greek, "time" meaning (the following usage in the production environment of the server is very useful, fuqin cooking wine strongly recommended); The basic usage and syntax of Crontab I don't recommend it, Google and 51cto are everywhere, I'm talking about advanced techniques that may not be known; shell scripts are taken from online servers. I installed the server is generally a minimal installation, after installation found that the launch of Cron Management Services Crond default is started.

Service Crond Status

Crond (PID 3444) is running ...

Hands's boys can be chkconfig crond on to make them run automatically in Level3 and Level5.

Cron stores the command line in a crontab (cron table) file, which is usually in the/etc directory. Each system user can have its own crontab (under/var/spool/cron/).

To view the current user's crontab, enter crontab-l

To edit crontab, enter CRONTAB-E

To delete crontab, enter Crontab-r

If you are currently root, to view/edit/delete/crontab a user, simply add-u USERNAME (such as crontab-e-U USERNAME) after the corresponding command. The default editor for crontab files is VI, which you can enter

Export visual= ' editor '

Change the default editor.

The Cron service will not only read all the files in the/var/spool/cron directory once per minute, but also read the/etc/crontab files once. Configuring this file also allows Cron to perform tasks. Using the crontab command is a configuration of user-level tasks, while editing/etc/crontab files is a configuration of system-level tasks.

Fuqin boiling wine definition of crontab grammar better remember, recommend memory learning

Time and time of the week user with absolute path command script or PHP detail path

Careful you find no, crontab minimum execution time is minutes, if the task is a second-level how to do, in fact, there is a way, I will take an example to illustrate; server I suggest also to/etc/crontab mainly, it is more convenient to control user management; suggest that scheduled tasks on the server are staggered , do not parallel tasks, or will be in a certain time period caused the system load too large, make your nagios mad send the alarm mail.

Playing Windows should also find that every time the password for the WINDOWS2K series is modified by the sysadmin administrator is a mammoth project, and every scheduled task in Windows Scheduler to change the password CentOS to modify the root password is much simpler, a passwd command to solve the problem, and does not affect the implementation of crontab.

After each JOB completes, the system automatically sends the output to the current system user. Over and over, very much, even the whole system will explode. So it is necessary to redirect each JOB command back: "/dev/null 2>&1." The premise is that the command in the JOB requires normal output has done some processing, such as appending to a particular log file;/dev/null 2>&1 says that all standard output is sent to/dev/null (the Linux Recycle Bin). The standard error output (2) is sent to the same place (i.e./dev/null) as the standard output (1). Running this line of command will not produce any output. Examples are as follows:

6 1 * Root tar czf/usr/local/backups/daily/etc.tar.gz/etc "/dev/null 2>&1

Centos/freebsd the correct way to execute PHP program with Crontab is as follows:

Under Linux, you can use the Crontab+php method:

1. Use Crontab–e to edit timed tasks

Content is:

XX:XX:XX executes a test.php file

2, the PHP file must be in the first line of the file, plus the interpreter path (as Perl did)

#!/usr/local/bin/php

The execution of PHP requires Apache support, the execution of the shell script requires Linux support, and Linux supports the ability to run a program on a regular basis.

---------------------------------------------------------------

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.