Installing the crontab service in CentOS

Source: Internet
Author: User
Tags echo date

Installing the crontab service in CentOS
Today, when I configured crontab on the test machine, I found that it was not installed, so I had to install one quickly.

CentOS version: 5.7

Procedure

1. Check whether crontab is installed:

Execute the crontab command. If command not found is reported, it indicates that the crontab is not installed.

2. Install crontab

Run yum install-y vixie-cron

3. confirm whether the installation is successful:

Execute crontab-e


4. Check whether Automatic startup is enabled.

Chkconfig -- list crond

5. Start crontab

Service crond start




Detailed records


[Root @ node16 eap_designer] # crontab-e
-Bash: crontab: command not found
[Root @ node16 eap_designer] # yum install-y crontab
Loaded plugins: fastestmirror
Determining fastest mirrors
* Base: centos.ustc.edu.cn
* Extras: centos.ustc.edu.cn
* Updates: centos.ustc.edu.cn
Base | 1.1 kB
Extras | 2.1 kB: 00
Extras/primary_db | 171 kB: 00
Updates | 1.9 kB: 00
Updates/primary_db | 464 kB
Setting up Install Process
No package crontab available.
Nothing to do
[Root @ node16 eap_designer] # yum install-y cron
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Base: centos.ustc.edu.cn
* Extras: centos.ustc.edu.cn
* Updates: centos.ustc.edu.cn
Setting up Install Process
No package cron available.
Nothing to do
[Root @ node16 eap_designer] # yum install-y crond
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Base: centos.ustc.edu.cn
* Extras: centos.ustc.edu.cn
* Updates: centos.ustc.edu.cn
Setting up Install Process
No package crond available.
Nothing to do
[Root @ node16 eap_designer] # yum install-y crontab
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Base: centos.ustc.edu.cn
* Extras: centos.ustc.edu.cn
* Updates: centos.ustc.edu.cn
Setting up Install Process
No package crontab available.
Nothing to do
[Root @ node16 eap_designer] # yum install-y crontabs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Base: centos.ustc.edu.cn
* Extras: centos.ustc.edu.cn
* Updates: centos.ustc.edu.cn
Setting up Install Process
Package crontabs-1.10-8.noarch already installed and latest version
Nothing to do
[Root @ node16 eap_designer] # crontab
-Bash: crontab: command not found



[Root @ node16 eap_designer] # cd
[Root @ node16 ~] #
[Root @ node16 ~] #

I checked the information to know that it is not cron, crond, crontab, crontabs, but vixie-cron.
[Root @ node16 ~] # Yum install-y vixie-cron
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Base: centos.ustc.edu.cn
* Extras: centos.ustc.edu.cn
* Updates: centos.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vixie-cron.i386. 1-77.el5_4.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

========================================================== ========================================================== ========================================================== ================
Package Arch Version Repository Size
========================================================== ========================================================== ========================================================== ================
Installing:
Vixie-cron i386 4:4. 1-77.el5_4.1 base 79 k

Transaction Summary
========================================================== ========================================================== ========================================================== ================
Install 1 Package (s)
Upgrade 0 Package (s)

Total download size: 79 k
Downloading Packages:
Vixie-cron-4.1-77.el5_4.1.i386.rpm | 79 kB
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: vixie-cron 1/1

Installed:
Vixie-cron.i386 4: 4. 1-77.el5_4.1

Complete!



[Root @ node16 ~] # Crontab-l
No crontab for root
[Root @ node16 ~] #
[Root @ node16 ~] # Chkconfig -- list crontab
An error occurred while reading information in the crontab service: the file or directory does not exist.
[Root @ node16 ~] # Chkconfig -- list cron
An error occurred while reading information in the cron service: the file or directory does not exist.
[Root @ node16 ~] # Chkconfig -- list
Anacron 0: off 1: off 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Avahi-daemon 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Avahi-dnsconfd0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close
Crond 0: off 1: off 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Gpm 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Haldaemon 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Iscsi 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Iscsid 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Jexec 0: Enable 1: Enable 2: Enable 3: Enable 4: Enable 5: Enable 6: Enable
Kudzu 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Lvm2-monitor 0: off 1: Enable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Mcstrans 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Messagebus 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Multipathd 0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close
Mysql 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Netconsole 0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close
Netfs 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Netplugd 0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close
Network 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Rawdevices 0: Disable 1: Disable 2: Disable 3: Enable 4: Enable 5: Enable 6: Disable
Rdisc 0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close
Restorecond 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Sshd 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Syslog 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Tcsd 0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close
Xfs 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
[Root @ node16 ~] # Chkconfig -- list crond
Crond 0: off 1: off 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
[Root @ node16 ~] # Service crond
Usage:/etc/init. d/crond {start | stop | status | reload | restart | condrestart}
[Root @ node16 ~] # Service crond status
Crond stopped
[Root @ node16 ~] #


[Root @ node16 ~] #
[Root @ node16 ~] # Service crond start
Start crond: [OK]
[Root @ node16 ~] # Service crond status
Crond (pid16932) is running...

[Root @ node16 ~] #

After completing the above basic work, let's see how to use crontab to regularly execute the PHP script:
(1) I create the test. php file under/root. The content is as follows:
 
  1. <? Php
  2. #! /Usr/bin/php-q
  3. Echo date ('Y-m-d H: I: s'). "from http://www.phpddt.com \ n ";
  4. ?>
Note: You can use whereis php to find the location of the php Execution file. Enter php-q test. php In the command line to test whether the PHP program you wrote can run normally (2). Then crontab-e writes the following shell:
 
 
  1. * ***/Usr/bin/php-f/root/test. php> test. log
Note: test. php must be an executable file: chmod + x test. php test results are normal. Of course, you can use crontab-e to continue adding tasks. Under/var/spool/cron, you can see a root file. We can see that you can use tail-f/var/log/cron to observe the log. You can also use ps-aux | grep cron to view all processes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.