BKJIA exclusive Article] Have you used Crontab? Do you know about Crontab? Do you know how to execute tasks in seconds? Do you know how to let Crontab execute the PHP script? Do you know some special functions of Crontab? In this article, fuqin will introduce you to the experience of using Crontab over the years.
By Andrew Yu)
Occupation: Linux/unix system engineer and project implementation Engineer
Server System: 64Bit CentOS 5.5
Although the introduction of Crontab is everywhere, after reading this entry in detail, we still have some gains. Crontab is named "chronos". It is an ancient Greek term and "time". The following uses are very useful for servers in the production environment. It is strongly recommended that you cook Crontab ); I will not recommend the basic usage and syntax of crontab. google and 51cto are everywhere. I am talking about some advanced techniques, which may be unknown; shell scripts are taken from online servers. The servers I installed are generally installed with minimal installation. After installation, I found that the cron Management Service is started by default,
service crond statuscrond (pid 3444) is running...
Quick guy can use chkconfig crond on to make it run automatically in level3 and level5.
Cron saves the command line in the crontabcron table file, which is usually in the/etc directory. Each system user can have their own crontab under/var/spool/cron ). To view the crontab of the current user, enter
crontab -l
To edit crontab, enter
crontab -e
To delete the crontab, enter
crontab -r
If the current identity is root, to View/Edit/delete/crontab of a user, add-u USERNAME such as crontab-e-u USERNAME to the corresponding command. The Default Editor of the crontab file is vi. You can enter
export VISUAL='editor'
Change the default editor.
The cron service reads not only all files in the/var/spool/cron directory once per minute, but also the/etc/crontab file once. Configuring this file also allows cron to execute tasks. The crontab command is used to configure user-level tasks, and editing the/etc/crontab file is used to configure system-level tasks.
The crontab syntax defined by fuqin liquor is easy to remember and recommended for memory learning.
MinuteHourDayMonthWeekUserCommand with absolute pathScript or PHPDetailed path
You may find that the minimum crontab execution time is minutes. If you want the task to be executed in seconds, there is actually a way to do it. I will explain it with examples; I recommend that you use/etc/crontab for the server to facilitate user management. We recommend that you stagger the scheduled task time on the server and avoid parallel tasks at the same time, otherwise, the system load will be too high during a certain period of time, causing your Nagios to send an alert email.