问题
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
:
Ctrl-c
your/usr/local/bin/php Import_Product_Data.php
.- Move the cursor to the first empty line
- Press
i
into thevi
console- Paste using your mouse.
- Hit
ESC
.- Write
:wq
.- 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