Crontab Concept/Introduction
The crontab command is used to set instructions that are periodically executed. This command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution.
Cron system scheduling process. You can use it to run a job on a daily off-peak load time period, or at different times o
Crontab Problem Analysis
Problem Analysis:1. crontab is not executed. 2. The current file is not an executable file 3. the syntax of the shell file called by crontab is incorrect.
Solution:1. Check whether crontab is being executed. The scheduled tasks that have been executed are listed here.
tail -f /var/
tasks, but also can generate crontab configuration files, the resulting configuration can be selected to export to the file, can also be directly output to the screen.
The resulting configuration is shown in the following illustration:
This generated configuration is more humane to redirect the results to the/dev/null, avoiding the frequent sending of log files. It also shows the next 5 task execution ti
file.Write the command and time that you want to execute in the crontab file, where each row contains six fields, the first five of which are the time that the specified command was executed, and the last domain is the command to be executed. Spaces or tabs are used to separate each field. The format is as follows:
Minute hour day-of-month month-of-year day-of-week commands
Valid values are: 00-59 00-23 01-31 01-12 0-6 (0 i
The Linux crontab command, the minimum execution time is one minute. If you need to repeat within less than a minute, there are two ways to implement it.1, using delay to achieve every n seconds executionPrinciple: The time delay method sleep N to implement every n seconds.Creating a PHP execution action is as simple as writing the current time to log.phpfile_put_contents ('/root/pengjun/php/crontab/run.log
minutes from 18:00 to 23:00 every day. 0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart The above example indicates that every Saturday 11:00 PM Restart LIGHTTPD. * */1 * * * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart Restart every hour lighttpd * 23-7/1 * * */usr/local/etc/rc.d/lighttpd restart 11 o'clock to 7 in the morning and restarts every hour lighttpd 0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart 4th per month and 11-point restart from Monday to Wednesday lighttpd 0 4 1 Jan */USR/LOCAL/ET
I set up two scheduled tasks, which are scheduled to restart the service, as follows:
[root@iZ94r80gdghZ tanteng]# crontab -l# 系统计划任务* */1 * * * service mariadb restart >> /home/tanteng/crontab.log* * */1 * * service php70-php-fpm restart >> /home/tanteng/crontab.log
I just put the command statements in the back of the scheduled task can be, these commands in the machine can be run, while the output recorded to the
users, but have sufficient permissions My_user_cron = crontab (user=true) # Create Task job = My_ User_cron.new (command= ' echo date >> ~/time.log ') # Set the task execution cycle, execute job.setall every two minutes (' */2 * * * * ') # and of course support other more humane settings, Simply list some job.minute.during (5,50). Every (5) job.hour.every (4) Job.day.on (4, 5, 6) Job.dow.on (' Sun ') job.dow.on (' Sun ', ' FRI ') job.month.during ('
Routine work arrangement for crontab in Linux
1. What is crontab?
Periodically process the daemons for to-do items, and the class dead task schedule.
2.crontab command resolution.
Example:
0 0 * * 1-5 cd/home/hiperry;/shutdwon.sh >/logs/shutdwon.log 2>1
--Executes a custom shutdown script at 12 o'clock every night and writes
First, the phenomenon of failure
Connect the business side colleague phone, one of the server can not SSH normal connection, also received the downtime SMS alert information. Ping directly the next host address can ping, SSH port connection hint: Ssh_exchange_identification:connection closed by remote host. View the error by admin port login: "Login:failure forking:cannot allocate Memory/etc/initscript:fork:cannot allocate memory". Screenshot below:
Second, fault analysis and treatment
1. F
time you will be prompted to use the compiler, you can just select one)
Then you can enter the content you want to execute.
For example, */2 ***** date>/home/postgres/time. log indicates the system time of course written to the time. log file every two minutes.
Then press ctrl + X to exit and save.
2. After saving crontab, restart the
In Oracle databases, backup scripts can be executed on the command line, but cannot be executed on crontab. How to determine whether crontab is available for oracle users in Linux?
In Oracle databases, backup scripts can be executed on the command line, but cannot be executed on crontab. How to determine whether crontab
day.(2) The timestamp of the most recent run Anacron was taken out by/var/spool/anacron/cron.daily.(3) Compare the time stamp taken with the current timestamp, and if the difference is more than one day, prepare the command.(4) If the order is ready, the delay will be 65 minutes according to the/etc/anacrontab configuration.(5) After the delay time, start to run the subsequent command, that is, run-parts/etc/cron.daily this sequence of commands.(6) After the operation is complete, the Anacron p
Linux scheduling Task Cron is a timed mode, for example, we can back up the system at least when the system is used, but it is impossible for an administrator to come to work in the middle of the night, so you can use the Linux program task Cron, now to explain how to use it.
Currently popular Linux systems are installed and are randomly activated after installation.
Start cron service/sbin/service Crond start
Stop service/sbin/service Crond stop
Restart Service/sbin/service Crond restart
R
1. crontabIntroduction
The crontab command schedules the execution of some commands at certain intervals.
1.1/etc/crontab file
There is a crontab file in the/etc directory, which stores some scheduling programs that are running systematically. Each user can create their own scheduling crontab.
For example:
[Root @ D
the situation.View Log->/var/log/syslogYou can find the problem that appears in the log file: No MTA installed, discarding output .According to find the data found Crontab execution script is not directly wrong information output, but will be sent in the form of mail to your mailbox, this time you need a mail server,
file writtenView crontab tasks$ Crontab-l# Begin Plan generated jobs for: main* *** Cd/home/ubuntu/schedule/bash ./OneMinutesTask. sh# End Plan generated jobs for: mainOK. The test runs successfully. Use the python script to configure crontab to run the script more readable and better maintained.IV. FAQs1. You are not sure whether the task is running. You can go
1. Manually perform timed tasks to determine if there is a problem with the script.
2, confirm that the server is open scheduled task scheduling services
Command: Service crond status
service Crond start1 2
3, check the timing task configuration syntax
Crontab-l
shell=/bin/bash
0 * * 1-5 cd/root/ye/project/statsharedataproject/./start.sh1 2 3
Can be directly copied cd/root/ye/project/statsharedataproject/./start.sh to
Linux crontab usage notes1. InstallService crond statusYum install vixie-cronYum install crontabs2. InstancePrint the current time to the log file every minute# Crontab-e*/1 ***** date>/tmp/date.txt# Tail-f/tmp/date.txt (this file is dynamically displayed)# Crontab-e-u username0-58/2 *** echo "EVEN *** \ n"#
: Used in conjunction with-R to allow users to selectively remove assigned tasks in interactive mode;-U User: Only root can run, on behalf of the designated users to manage cron tasks;Note: The results of the operation are notified to the relevant users by mail, and if you do not want to receive mail, use the following command(1) COMMAND >/dev/null(2) COMMAND >/dev/nullThinking:(1) How do I run a task at the second level?* * * * * for min in 0 1 2; Do echo "HI"; Sleep 20; Done(2) How do I run a
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.