[root@jiangbo ~]# crontab -u root -l no crontab for root [root@jiangbo ~]# crontab -u root -e no crontab for root - using an empty one crontab: installing new crontab [root@jiangbo ~]# crontab -u root -l */1 * * * * ls >> /tmp/ls.txt [root@jiangbo ~]#
*/1 * * * * /usr/bin/php /var/www/html/testcrontab.php
<?php $myfile = fopen("/var/www/html/newfile.txt", "a+");//這里寫相對路徑不行 //or die("Unable to open file!!"); $txt = "Bill Gates\n"; fwrite($myfile, $txt); $txt = "Steve Jobs\n"; fwrite($myfile, $txt); fclose($myfile); ?>
[root@jiangbo ~]# /usr/bin/php /var/www/html/xiaochu/test/testGame.php
PHP Warning: require_once(../Amfphp/app/util/Mpdo.class.php): failed to open stream: No such file or directory in /var/www/html/xiaochu/test/testGame.php on line 2
PHP Fatal error: require_once(): Failed opening required '../Amfphp/app/util/Mpdo.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/xiaochu/test/testGame.php on line 2
[root@jiangbo ~]# crontab -l
*/1 * * * * /usr/bin/php /var/www/html/xiaochu/test/testGame.php
You have new mail in /var/spool/mail/root
[root@jiangbo ~]#
/usr/bin/php 這樣執行的話好像不認相對路徑,只能通過URL方式定時執行了
[root@jiangbo ~]# /etc/init.d/mysqld start Another MySQL daemon already running with the same unix socket. 正在啟動 mysqld: [失敗] [root@jiangbo ~]# /etc/init.d/mysqld start 正在啟動 mysqld: [確定] [root@jiangbo ~]#
刪除/var/lib/mysql/mysql.sock 文件就行了
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啟服務
/sbin/service crond reload //重新載入配置
/sbin/service crond start
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //如果出現錯誤,或者有數據輸出,數據作為郵件發給這個帳號
HOME=/ //使用者運行的路徑,這里是根目錄
# run-parts
01 * * * * root run-parts /etc/cron.hourly //每小時執行/etc/cron.hourly內的腳本
02 4 * * * root run-parts /etc/cron.daily //每天執行/etc/cron.daily內的腳本
22 4 * * 0 root run-parts /etc/cron.weekly //每星期執行/etc/cron.weekly內的腳本
42 4 1 * * root run-parts /etc/cron.monthly //每月去執行/etc/cron.monthly內的腳本
