I can't set cron job
I've tried to set a cron job in "crontab -e":
* * * * * /usr/bin/php /home/vagrant/Code/xxx/testCron.php
testCron.php file creates another file, it contains only this:
<?php
$f = fopen('cron-' . date('H-i-s') . '.txt', 'w+');
fwrite($f, 'asdf');
fclose($f);
But the file cron-....txt doesn't appear. Were can be a problem?
I did/checked this:
You can check the log from cron jobs to identify errors.
Depending on your system, the cron log can be located in different places. Find the files containing cron logs:
grep -ic cron /var/log/* | grep -v :0
./auth.log:1246
./auth.log.1:3054
./bootstrap.log:3
./syslog:187
./syslog.1:220
Then view the contents of the log in question, eg via cat
:
cat /var/log/syslog
Or view the latest run of testCron.php in that file:
grep -i testCron.php /var/log/syslog | tail -1
Your script creates the cron-...txt
file with no path; therefore it appears in the current directory - if it has write permission. Cronjobs will have a different start directory - usually the user's home, but may be anywhere, depending on configuration.
Try one of these:
下一篇: 我无法设置cron作业