How to add a cron job to run php script

无人久伴 提交于 2019-12-12 03:36:09

问题


I have a php script I'm trying to run using a cron job. I can execute the script from CLI doing

/usr/local/bin/php Import_Product_Data.php

So I have tried..

0 0 * * * /usr/local/bin/php Import_Product_Data.php

and

crontab 0 0 * * * /usr/local/bin/php Import_Product_Data.php

and

crontab -e 0 0 * * * /usr/local/bin/php Import_Product_Data.php

Vince V. says to open your cronfile and do it.. When I enter crontab -e, I get

*/5 * * * * /root/autosvnup.sh
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/tmp/crontab.ZBGTFu" 1L, 31C

Then I get stuck and not sure what to do.. Would someone help me out?


回答1:


That's the vi editor, your default text editor (check man vi). Here are the commands to edit your crontab with vi:

  1. Ctrl-c your /usr/local/bin/php Import_Product_Data.php.
  2. Move the cursor to the first empty line
  3. Press i into the vi console
  4. Paste using your mouse.
  5. Hit ESC.
  6. Write :wq.
  7. Hit RETURN.



回答2:


What you're seeing is the vim text editor. When you do crontab -e it opens up your crontab in the default editor. The default editor can be changed by, for example:

export EDITOR=nano

..some find nano a lot easier to work with as vim has a somewhat steep learning curve.

To add your script to the crontab, just insert it on a new line, so that your crontab looks like this:

*/5 * * * * /root/autosvnup.sh
0 0 * * * /usr/local/bin/php Import_Product_Data.php

Then save+exit, and it should run once every midnight (as per the 0 0 * * *)



来源:https://stackoverflow.com/questions/13845021/how-to-add-a-cron-job-to-run-php-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!