在服务器上运行 crontab -e编辑定时任务 结果提示 command not found命令找不到,这就说明没安装crontab
由于
完整操作如下:
[[email protected] /]# yum install vixie-cron crontabs Loaded plugins: security Setting up Install Process Package cronie-1.4.4-15.el6_7.1.x86_64 already installed and latest version Package crontabs-1.10-33.el6.noarch already installed and latest version Nothing to do [[email protected] /]# crontab -l no crontab for root [[email protected] /]# service crond status crond is stopped [[email protected] /]# service crond start Starting crond: [ OK ] [[email protected] /]# ntsysv [[email protected] /]# chkconfig –level 35 crond on chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc. This may be freely redistributed under the terms of the GNU Public License. usage: chkconfig [--list] [--type <type>] [name] chkconfig --add <name> chkconfig --del <name> chkconfig --override <name> chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities> [[email protected] /]# crontab -e no crontab for root - using an empty one crontab: no changes made to crontab
分步操作为
开始安装 运行
yum install vixie-cron crontabs
然后它返回很多
Loaded plugins: security base epel epel/primary_db extras updates Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package cronie.x86_64 0:1.4.4-15.el6_7.1 will be installed --> Processing Dependency: dailyjobs for package: cronie-1.4.4-15.el6_7.1.x86_64 --> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-15.el6_7.1.x86_64 --> Running transaction check ---> Package cronie-anacron.x86_64 0:1.4.4-15.el6_7.1 will be installed --> Processing Dependency: crontabs for package: cronie-anacron-1.4.4-15.el6_7.1.x86_64 ---> Package exim.x86_64 0:4.84.2-3.el6 will be installed --> Running transaction check ---> Package crontabs.noarch 0:1.10-33.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================================== Package Arch Version ==================================================================================================================================================================== Installing: cronie x86_64 1.4.4-15.el6_7.1 Installing for dependencies: cronie-anacron x86_64 1.4.4-15.el6_7.1 crontabs noarch 1.10-33.el6 exim x86_64 4.84.2-3.el6 Transaction Summary ==================================================================================================================================================================== Install 4 Package(s) Total download size: 1.4 M Installed size: 4.2 M Downloading Packages: (1/4): cronie-1.4.4-15.el6_7.1.x86_64.rpm (2/4): cronie-anacron-1.4.4-15.el6_7.1.x86_64.rpm (3/4): crontabs-1.10-33.el6.noarch.rpm (4/4): exim-4.84.2-3.el6.x86_64.rpm -------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : exim-4.84.2-3.el6.x86_64 Installing : cronie-1.4.4-15.el6_7.1.x86_64 Installing : crontabs-1.10-33.el6.noarch Installing : cronie-anacron-1.4.4-15.el6_7.1.x86_64 Verifying : crontabs-1.10-33.el6.noarch Verifying : cronie-1.4.4-15.el6_7.1.x86_64 Verifying : exim-4.84.2-3.el6.x86_64 Verifying : cronie-anacron-1.4.4-15.el6_7.1.x86_64 Installed: cronie.x86_64 0:1.4.4-15.el6_7.1 Dependency Installed: cronie-anacron.x86_64 0:1.4.4-15.el6_7.1 crontabs.noarch 0:1.10-33.el6 Complete!
然后我运行 crontab -l
提示 no crontab for root
然后我查看crontab服务状态
service crond status
它提示 crond is stopped
然后我运行service crond start
它提示 Starting crond: [ OK ]
然后我查看开机启动项 ntsysv
然后界面是
然后我把这个服务加入开机服务中 chkconfig –level 35 crond on
然后它提示
[[email protected] /]# chkconfig –level 35 crond on chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc. This may be freely redistributed under the terms of the GNU Public License. usage: chkconfig [--list] [--type <type>] [name] chkconfig --add <name> chkconfig --del <name> chkconfig --override <name> chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>
然后我 crontab -e 就进入了定时任务的编辑界面中
时间: 2024-10-31 14:29:42