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:
Configuration files: Set up Scheduled tasks as a file
System Services (Crond): Refreshes the scheduled task from the configuration file every minute
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
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.
Crontab's Log
- Log Address:/var/log/cron
Scheduled Tasks in Linux crontab