Yes, I have read many, many documentations but I can't get it to work. I have a simple single php file which I want to run once or twice in a minute. My php file is called: cronjob_refresh.php and I'm using Ubuntu 12.
After typing
crontab -e
I'm getting in terminal:
root@cron:~# crontab -e
no crontab for root – using an empty one
888
I don't know what '888' is meaning… And I'm writing (after 888) my cronjob string
*/1 * * * * php /var/www/cronjob/cronjob_refresh.php
After hitting enter I'm getting '?' symbol after the cronjob string entered.
root@cron:~# crontab -e
no crontab for root – using an empty one
888
*/1 * * * * php /var/www/cronjob/cronjob_refresh.php
?
Then I hit CTRL + Z to exit. After all this I'm executing
crontab -l
to check if the cronjob is added to my cronjob list but it's saying that the list is empty.
I don't know what I'm doing wrong. Also I wan't to execute twice in a minute, 30 – 30 sec. How to set the cronjob? I want to log everything in a file named logs.log in the same directory, is this is possible?
Best Answer
888 is the number of characters in the default Ubuntu crontab file (22 lines of information all commented out).
Typing ^Z doesn't save anything it puts the job in the background - read up on job control.
You should set your editor preference before running
crontab -e
export EDITOR=vi
orexport EDITOR=nano
Cron only works with 1 minute resolution so 30 seconds would require your script to do something.
To forestall other questions about your php not working (because there are errors in your crontab specification) please read our canonical question & answer on the subject.