linux crontab yum安装

crontab工具来做计划任务,定时任务,执行某个脚本等等

1.检查是否已安装crontab    

# crontab

-bash: crontab: command not found

  

   执行 crontab 命令如果报 command not found,表明没有安装.

2.yum安装       

  

 1 # yum -y install vixie-cron
 2 Loaded plugins: security
 3 base                                                                                                                                                                    | 3.7 kB     00:00     
 4 epel                                                                                                                                                                    | 4.7 kB     00:00     
 5 epel/primary_db                                                                                                                                                         | 6.0 MB     00:00     
 6 extras                                                                                                                                                                  | 3.4 kB     00:00     
 7 extras/primary_db                                                                                                                                                       |  29 kB     00:00     
 8 updates                                                                                                                                                                 | 3.4 kB     00:00     
 9 updates/primary_db                                                                                                                                                      | 5.3 MB     00:00     
10 Setting up Install Process
11 Resolving Dependencies
12 --> Running transaction check
13 ---> Package cronie.x86_64 0:1.4.4-16.el6_8.2 will be installed
14 --> Processing Dependency: dailyjobs for package: cronie-1.4.4-16.el6_8.2.x86_64
15 --> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.x86_64
16 --> Running transaction check
17 ---> Package cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 will be installed
18 --> Processing Dependency: crontabs for package: cronie-anacron-1.4.4-16.el6_8.2.x86_64
19 ---> Package exim.x86_64 0:4.89-2.el6 will be installed
20 --> Running transaction check
21 ---> Package crontabs.noarch 0:1.10-33.el6 will be installed
22 --> Finished Dependency Resolution
23 
24 Dependencies Resolved
25 
26 ===============================================================================================================================================================================================
27  Package                                           Arch                                      Version                                             Repository                               Size
28 ===============================================================================================================================================================================================
29 Installing:
30  cronie                                            x86_64                                    1.4.4-16.el6_8.2                                    base                                     75 k
31 Installing for dependencies:
32  cronie-anacron                                    x86_64                                    1.4.4-16.el6_8.2                                    base                                     31 k
33  crontabs                                          noarch                                    1.10-33.el6                                         base                                     10 k
34  exim                                              x86_64                                    4.89-2.el6                                          epel                                    1.4 M
35 
36 Transaction Summary
37 ===============================================================================================================================================================================================
38 Install       4 Package(s)
39 
40 Total download size: 1.5 M
41 Installed size: 4.3 M
42 Downloading Packages:
43 (1/4): cronie-1.4.4-16.el6_8.2.x86_64.rpm                                                                                                                               |  75 kB     00:00     
44 (2/4): cronie-anacron-1.4.4-16.el6_8.2.x86_64.rpm                                                                                                                       |  31 kB     00:00     
45 (3/4): crontabs-1.10-33.el6.noarch.rpm                                                                                                                                  |  10 kB     00:00     
46 (4/4): exim-4.89-2.el6.x86_64.rpm                                                                                                                                       | 1.4 MB     00:00     
47 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
48 Total                                                                                                                                                           10 MB/s | 1.5 MB     00:00     
49 Running rpm_check_debug
50 Running Transaction Test
51 Transaction Test Succeeded
52 Running Transaction
53   Installing : exim-4.89-2.el6.x86_64                                                                                                                                                      1/4 
54   Installing : cronie-1.4.4-16.el6_8.2.x86_64                                                                                                                                              2/4 
55   Installing : crontabs-1.10-33.el6.noarch                                                                                                                                                 3/4 
56   Installing : cronie-anacron-1.4.4-16.el6_8.2.x86_64                                                                                                                                      4/4 
57   Verifying  : crontabs-1.10-33.el6.noarch                                                                                                                                                 1/4 
58   Verifying  : cronie-anacron-1.4.4-16.el6_8.2.x86_64                                                                                                                                      2/4 
59   Verifying  : exim-4.89-2.el6.x86_64                                                                                                                                                      3/4 
60   Verifying  : cronie-1.4.4-16.el6_8.2.x86_64                                                                                                                                              4/4 
61 
62 Installed:
63   cronie.x86_64 0:1.4.4-16.el6_8.2                                                                                                                                                             
64 
65 Dependency Installed:
66   cronie-anacron.x86_64 0:1.4.4-16.el6_8.2                                crontabs.noarch 0:1.10-33.el6                                exim.x86_64 0:4.89-2.el6                               
67 
68 Complete!

 

 

 

安装完成后,可使用 info crontab 命令查看详细的帮助信息

cron服务提供crontab命令来设定cron服务的,以下是这个命令的一些参数与说明:

  crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数

  crontab -l //列出某个用户cron服务的详细内容

  crontab -r //删除没个用户的cron服务

  crontab -e //编辑某个用户的cron服务

  比如说root查看自己的cron设置:crontab -u root -l

  再例如,root想删除fred的cron设置:crontab -u fred -r

  在编辑cron服务时,编辑的内容有一些格式和约定,输入:crontab -u root -e

crontab服务状态操作

  /sbin/service crond start //启动服务 
  /sbin/service crond stop //关闭服务 
  /sbin/service crond restart //重启服务 
  /sbin/service crond reload //重新载入配置 
  /sbin/service crond status //查看状态

或者使用

  # service crond start 
  # service crond stop 
  # service crond restart 
  # service crond reload 
  # service crond status

添加到开机服务

  在/etc/rc.d/rc.local这个脚本的末尾加上:

    /sbin/service crond start

posted @ 2017-12-21 17:20  HIXIAODENG  阅读(10232)  评论(0编辑  收藏  举报