简体   繁体   中英

Running php script using cron on a Mac

What is wrong with this cronjob?

* * * * * * php -f /Documents/Programs/WeeklyHours/weekly_hour.php

I have combed through the various cron questions on StackExchange and nothing is working. When I run php -f /Documents/Programs/WeeklyHours/weekly_hour.php in the terminal it works perfectly. I know the cron jobs are running because I am getting error mail. At the bottom of the error mail messages it is saying "/bin/sh: Applications: command not found." Any ideas on what I am doing wrong?

Thanks in advance.

You have one more * than required in your crontab entry

Try

0-59 * * * * php -f /Documents/Programs/WeeklyHours/weekly_hour.php

The 0-59 is so that it will run every minute

The cron job likely runs under a different user which does not have its PATH set up the same as you, so it cannot find the php executable. You are able to simply type php because your PATH variable is set up to include its parent directory; that is not necessarily true for all other users.

Explicitly specify the path to the executable, eg /usr/bin/php . To figure out which php you're using, type:

$ which php
 * * * * * * /usr/local/bin/php -f /Documents/Programs/WeeklyHours/weekly_hour.php >> /ww/xx.log 2>&1

您可以查看日志。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM