在服务器上运行 crontab -e编辑定时任务 结果提示 command not found命令找不到,这就说明没安装crontab
由于
完整操作如下:
[root@iZ11pvsxisqZ /]# yum install vixie-cron crontabsLoaded plugins: securitySetting up Install ProcessPackage cronie-1.4.4-15.el6_7.1.x86_64 already installed and latest versionPackage crontabs-1.10-33.el6.noarch already installed and latest versionNothing to do[root@iZ11pvsxisqZ /]# crontab -lno crontab for root[root@iZ11pvsxisqZ /]# service crond statuscrond is stopped[root@iZ11pvsxisqZ /]# service crond startStarting crond: [ OK ][root@iZ11pvsxisqZ /]# ntsysv[root@iZ11pvsxisqZ /]# chkconfig –level 35 crond onchkconfig 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] [name] chkconfig --add chkconfig --del chkconfig --override chkconfig [--level ] [--type ] [root@iZ11pvsxisqZ /]# crontab -eno crontab for root - using an empty onecrontab: no changes made to crontab
分步操作为
开始安装 运行
yum install vixie-cron crontabs
然后它返回很多
Loaded plugins: securitybase epel epel/primary_db extras updates Setting up Install ProcessResolving 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 ResolutionDependencies 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 MInstalled size: 4.2 MDownloading 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_debugRunning Transaction TestTransaction Test SucceededRunning 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
然后它提示
[root@iZ11pvsxisqZ /]# chkconfig –level 35 crond onchkconfig 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] [name] chkconfig --add chkconfig --del chkconfig --override chkconfig [--level ] [--type ]
然后我 crontab -e 就进入了定时任务的编辑界面中