關於根據 crontab 添加一個 1分鍾執行一次的命令 錯誤的執行和正確執行
錯誤的執行一:
[www@localhost www]$ crontab -e -u www * * * * * php think /www/index.php
crontab: usage error: no arguments permitted after this option
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
正確執行:
[www@localhost www]$ crontab -e -u www
默認使用vi編輯器來設定時程表
* * * * * php think /www/index.php
編輯好后,摁下ecs,:wq,保存退出;然后需要重啟crond,重啟需要root帳號
[www@localhost www]$ /sbin/service crond reload
Redirecting to /bin/systemctl reload crond.service
安裝crontab:
yum install crontabs
服務操作說明:
/sbin/service crond start //啟動服務
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啟服務
/sbin/service crond reload //重新載入配置
查看crontab服務狀態:
service crond status
手動啟動crontab服務:
service crond start
查看crontab服務是否已設置為開機啟動,執行命令:
ntsysv
加入開機自動啟動:
chkconfig –level 35 crond on