概述
利用“任务计划”,可以将任何脚本、程序或文档安排在某个最方便的时间运行。通俗的讲就是定时执行某个脚本、程序。
常见用途
定时关机
定时检查更新
定时对系统配置、数据库、日志进行备份
定时清理垃圾文件
检测是否已安装
# crontab
-bash: crontab: command not found
执行 crontab 命令如果报 command not found,就表明没有安装.
开始安装
# yum -y install vixie-cron
Loaded plugins: fastestmirror, refresh-packagekit, security
Existing lock /var/run/yum.pid: another copy is running as pid 25960.
Another app is currently holding the yum lock; waiting for it to exit...
可能是系统自动升级正在运行,yum在锁定状态中。
可以通过强制关掉yum进程:
#rm -f /var/run/yum.pid
然后就可以使用yum了。
# yum -y install vixie-cron
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.btte.net
* extras: mirrors.sina.cn
* updates: mirrors.sina.cn
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
extras/primary_db | 32 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 1.9 MB 00:07
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package cronie.x86_64 0:1.4.4-15.el6 will be installed
--> Processing Dependency: dailyjobs for package: cronie-1.4.4-15.el6.x86_64
--> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-15.el6.x86_64
--> Running transaction check
---> Package cronie-anacron.x86_64 0:1.4.4-15.el6 will be installed
--> Processing Dependency: crontabs for package: cronie-anacron-1.4.4-15.el6.x86_64
---> Package sendmail.x86_64 0:8.14.4-9.el6 will be installed
--> Processing Dependency: procmail for package: sendmail-8.14.4-9.el6.x86_64
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be installed
---> Package procmail.x86_64 0:3.22-25.1.el6_5.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved