2

I am trying to run in mac a php script using cron. I want this php script to run every one minute. I read several sources online and from my understanding is better if I use launchd. In any case, I try to make it work with cron and then if it works fine I might try to use launchd.

So here is what I do:

I wrote this command in a txt file:

    * * * * * /usr/bin/php /Applications/MAMP/htdocs/php_test/main_script.php

There I have the path to php (I found it with the "which php" command) and the path to my php script.

I named the txt file: crontasks.txt and I run it through terminal with this command:

       crontab /Users/dkar/Desktop/crontasks.txt

When I list the crons (crontab -l) I see that this job is listed. But nothing comes as output every one minute. The output is supposed to be an image stored in a specified folder. What am I missing here? Thanks in advance D.

1 Answer 1

4

You might have a slight miscomprehension how crond processes the "crontab" files. It would suffice to run the command crontab -e, which would let you edit your personal crontab or you edit the system crontab.

If you use crontab -e it will open the default editor (vi/vim) and you can enter the line:

  * * * * * /usr/bin/php /Applications/MAMP/htdocs/php_test/main_script.php

Then you simply save your file. If you want to use the system crontab you will have to edit it directly and enter the line. Additionally the system crontab has one more field for the username. Like this:

  * * * * * /usr/bin/php root /Applications/MAMP/htdocs/php_test/main_script.php

On the next full minute your script will be executed by crond.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer but when I run it I get this error: -bash: Adobe Dreamweaver CS5.5: command not found. I can not understand how dreamweaver is connected to this!
I found this article: htmlcenter.com/blog/running-php-scripts-with-cron which explains that if my php is installed using the apache module then I have to follow a different procedure.. (install lynx). But it doesn't seem to give me results either!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.