Install Crontab:
[email protected] ~]# Yum install Vixie-cron
[email protected] ~]# Yum install Crontabs
/sbin/service Crond Start #启动服务
/sbin/service Crond Stop #关闭服务
/sbin/service Crond Restart #重启服务
/sbin/service Crond Reload #重新载入配置
View crontab Service Status: Crond status
#查看crontab服务是否已设置为开机启动, execute command: NTSYSV
#加入开机自动启动: Chkconfig--level Crond on
#列出crontab文件 crontab-l or Crontab-u hadoop-l
#编辑crontab文件 crontab-e or Crontab-u hadoop-e
#删除crontab文件 $ crontab-r or crontab-u hadoop-r
Log file:/var/log/cron*
Basic format:
* * * * * command
Time-sharing Weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run
=========================== Command Chapter ===============================
* * * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that 21:30 restarts Apache per night.
4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.
1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.
0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows the restart of Apache every Saturday at 11:00am.
* */1 * * * */usr/local/etc/rc.d/lighttpd restart
Restart Apache every hour
* 23-7/1 * * * */usr/local/etc/rc.d/lighttpd restart
From 11 o'clock to 7 in the morning, restart Apache every hour.
* * * * * Date >>/home/date1.txt (front five * * * * * * indicates time is every minute the date command is the current system time, the >> command means that the result is added to the file > The command means that the result is covered Cover file)
===================sh article ==================================
[Email protected]/]# VI task.sh
task.sh inside the command
Date >>/home/date1.txt
Cp/home/date1.txt/date3.txt
At this point our task.sh is not an executable file, we can see it through the ls-l command
-rw-r--r--. 1 root root 54 April 6 16:27 task.sh//tash.sh is not enforceable, we want to modify its permissions
So we need to modify the permissions of task.sh through the chmod command:
[Email protected]/]# chmod 744 task.sh
Linux Crontab Learning