我们的网站youcl.com迁移到 digital ocean 新的VPS(CentOS的6.5)服务器之后,我们发现crontab在服务器上没有安装,当我尝试执行
的crontab -l命令,我发现下面的错误。
# crontab -l
-bash: crontab: command not found
在我们老的系统检查crontab命令的包后,我发现它来自
cronie包。因此,我认为把它写给youcl.com读者。使用下面的命令来安装它。这将安装所需的依赖
crontab的安装
# yum install cronie
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.web-ster.com
* updates: mirror.stanford.edu
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package cronie.x86_64 0:1.4.4-12.el6 will be installed
--> Processing Dependency: dailyjobs for package: cronie-1.4.4-12.el6.x86_64
--> Running transaction check
---> Package cronie-anacron.x86_64 0:1.4.4-12.el6 will be installed
--> Processing Dependency: crontabs for package: cronie-anacron-1.4.4-12.el6.x86_64
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
cronie x86_64 1.4.4-12.el6 base 73 k
Installing for dependencies:
cronie-anacron x86_64 1.4.4-12.el6 base 30 k
crontabs noarch 1.10-33.el6 base 10 k
Transaction Summary
==========================================================
Install 3 Package(s)
Total download size: 114 k
Installed size: 220 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): cronie-1.4.4-12.el6.x86_64.rpm | 73 kB 00:00
(2/3): cronie-anacron-1.4.4-12.el6.x86_64.rpm | 30 kB 00:00
(3/3): crontabs-1.10-33.el6.noarch.rpm | 10 kB 00:00
--------------------------------------------------------------------------------
Total 336 kB/s | 114 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : cronie-1.4.4-12.el6.x86_64 1/3
Installing : crontabs-1.10-33.el6.noarch 2/3
Installing : cronie-anacron-1.4.4-12.el6.x86_64 3/3
Verifying : crontabs-1.10-33.el6.noarch 1/3
Verifying : cronie-anacron-1.4.4-12.el6.x86_64 2/3
Verifying : cronie-1.4.4-12.el6.x86_64 3/3
Installed:
cronie.x86_64 0:1.4.4-12.el6
Dependency Installed:
cronie-anacron.x86_64 0:1.4.4-12.el6 crontabs.noarch 0:1.10-33.el6
Complete!
如何在crontab中添加新的任务
要添加新的cron用crontab -e在编辑器中编辑和添加的cron根据您的需求。在文件系统crons保存在文件
/var/spool/cron/<username>
# crontab -e
阅读以下文章,20个有用的例子来了解更多关于crontab。
https://www.youcl.com/info/10913
如何在crontab的作业列表
要列出下的crontab作业调度,我们可以使用
-l 命令行。例如,要列出工作计划的当前用户
# crontab -l
要查看在其他用户的调度作业中包含
-a 指定的用户名。
# crontab -u <username> -l