在CentOS下安装crontab服务
生活随笔
收集整理的這篇文章主要介紹了
在CentOS下安装crontab服务
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天在測(cè)試機(jī)上
配置crontab時(shí)發(fā)現(xiàn)它沒(méi)有
安裝,所以趕緊安裝一個(gè).
CentOS 版本:5.7
操作步驟
1. 確認(rèn)crontab是否安裝:
執(zhí)行 crontab 命令如果報(bào) command not found,就表明沒(méi)有安裝
2. 安裝 crontab
執(zhí)行 yum install -y vixie-cron
3. 確認(rèn)是否安裝成功:
4. 看是否設(shè)置了開(kāi)機(jī)自動(dòng)啟動(dòng)
chkconfig --list crond
5. 啟動(dòng)crontab
service crond start
詳細(xì)記錄
[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? ???00:00? ?
extras? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? | 2.1 kB? ???00:00? ?
extras/primary_db? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???| 171 kB? ???00:00? ?
updates? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?| 1.9 kB? ???00:00? ?
updates/primary_db? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? | 464 kB? ???00:01? ?
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 ~]#
查了一下資料,才知道它不叫cron,crond,crontab,crontabs,它叫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 4:4.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? ???00:00? ?
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
在 crontab 服務(wù)中讀取信息時(shí)出錯(cuò):沒(méi)有那個(gè)文件或目錄
[root@node16 ~]# chkconfig --list cron
在 cron 服務(wù)中讀取信息時(shí)出錯(cuò):沒(méi)有那個(gè)文件或目錄
[root@node16 ~]# chkconfig --list
anacron? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
avahi-daemon? ? 0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
avahi-dnsconfd??0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
crond? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
gpm? ?? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
haldaemon? ?? ? 0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
iscsi? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
iscsid? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
jexec? ?? ?? ???0:啟用??1:啟用??2:啟用??3:啟用??4:啟用??5:啟用??6:啟用
kudzu? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
lvm2-monitor? ? 0:關(guān)閉??1:啟用??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
mcstrans? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
messagebus? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
multipathd? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
mysql? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
netconsole? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
netfs? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
netplugd? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
network? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
rawdevices? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
rdisc? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
restorecond? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
sshd? ?? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
syslog? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
tcsd? ?? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
xfs? ?? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
[root@node16 ~]# chkconfig --list crond
crond? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
[root@node16 ~]# service crond
用法: /etc/init.d/crond {start|stop|status|reload|restart|condrestart}
[root@node16 ~]# service crond status
crond 已停
[root@node16 ~]#
[root@node16 ~]#
[root@node16 ~]# service crond start
啟動(dòng) crond:? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???[確定]
[root@node16 ~]# service crond status
crond (pid??16932) 正在運(yùn)行...
(1)我在/root下新建test.php文件,內(nèi)容如下:
<?php #!/usr/bin/php -q echo date('Y-m-d H:i:s')."from http://www.phpddt.com \n"; ?>
說(shuō)明:你可以用whereis php查找php執(zhí)行文件位置。 在命令行輸入php -q test.php 測(cè)試你寫(xiě)的PHP程序是否可以正常運(yùn)行
(2)然后crontab -e編寫(xiě)如下shell:
* * * * * /usr/bin/php -f /root/test.php >> test.log
說(shuō)明:test.php必須為可執(zhí)行文件:chmod +x test.php
測(cè)試結(jié)果很正常,截圖如下:
當(dāng)然你可以用使用crontab -e繼續(xù)添加任務(wù),在/var/spool/cron下你可以看到一個(gè)root文件。
可以看可以用tail -f /var/log/cron觀察日志
也可用ps -aux | grep cron 查看所有的進(jìn)程
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀
CentOS 版本:5.7
操作步驟
1. 確認(rèn)crontab是否安裝:
執(zhí)行 crontab 命令如果報(bào) command not found,就表明沒(méi)有安裝
2. 安裝 crontab
執(zhí)行 yum install -y vixie-cron
3. 確認(rèn)是否安裝成功:
執(zhí)行 crontab -e
4. 看是否設(shè)置了開(kāi)機(jī)自動(dòng)啟動(dòng)
chkconfig --list crond
5. 啟動(dòng)crontab
service crond start
詳細(xì)記錄
[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? ???00:00? ?
extras? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? | 2.1 kB? ???00:00? ?
extras/primary_db? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???| 171 kB? ???00:00? ?
updates? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?| 1.9 kB? ???00:00? ?
updates/primary_db? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? | 464 kB? ???00:01? ?
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 ~]#
查了一下資料,才知道它不叫cron,crond,crontab,crontabs,它叫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 4:4.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? ???00:00? ?
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
在 crontab 服務(wù)中讀取信息時(shí)出錯(cuò):沒(méi)有那個(gè)文件或目錄
[root@node16 ~]# chkconfig --list cron
在 cron 服務(wù)中讀取信息時(shí)出錯(cuò):沒(méi)有那個(gè)文件或目錄
[root@node16 ~]# chkconfig --list
anacron? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
avahi-daemon? ? 0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
avahi-dnsconfd??0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
crond? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
gpm? ?? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
haldaemon? ?? ? 0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
iscsi? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
iscsid? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
jexec? ?? ?? ???0:啟用??1:啟用??2:啟用??3:啟用??4:啟用??5:啟用??6:啟用
kudzu? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
lvm2-monitor? ? 0:關(guān)閉??1:啟用??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
mcstrans? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
messagebus? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
multipathd? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
mysql? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
netconsole? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
netfs? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
netplugd? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
network? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
rawdevices? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:啟用??4:啟用??5:啟用??6:關(guān)閉
rdisc? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
restorecond? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
sshd? ?? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
syslog? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
tcsd? ?? ?? ?? ?0:關(guān)閉??1:關(guān)閉??2:關(guān)閉??3:關(guān)閉??4:關(guān)閉??5:關(guān)閉??6:關(guān)閉
xfs? ?? ?? ?? ? 0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
[root@node16 ~]# chkconfig --list crond
crond? ?? ?? ???0:關(guān)閉??1:關(guān)閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關(guān)閉
[root@node16 ~]# service crond
用法: /etc/init.d/crond {start|stop|status|reload|restart|condrestart}
[root@node16 ~]# service crond status
crond 已停
[root@node16 ~]#
[root@node16 ~]#
[root@node16 ~]# service crond start
啟動(dòng) crond:? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???[確定]
[root@node16 ~]# service crond status
crond (pid??16932) 正在運(yùn)行...
[root@node16 ~]#
(1)我在/root下新建test.php文件,內(nèi)容如下:
說(shuō)明:你可以用whereis php查找php執(zhí)行文件位置。 在命令行輸入php -q test.php 測(cè)試你寫(xiě)的PHP程序是否可以正常運(yùn)行
(2)然后crontab -e編寫(xiě)如下shell:
說(shuō)明:test.php必須為可執(zhí)行文件:chmod +x test.php
測(cè)試結(jié)果很正常,截圖如下:
當(dāng)然你可以用使用crontab -e繼續(xù)添加任務(wù),在/var/spool/cron下你可以看到一個(gè)root文件。
可以看可以用tail -f /var/log/cron觀察日志
也可用ps -aux | grep cron 查看所有的進(jìn)程
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的在CentOS下安装crontab服务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux 设置网络
- 下一篇: centos下添加管理员组和添加管理员用