0

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?

3
  • Welcome to Server Fault! Your question is off topic for Serverfault because it doesn't appear to relate to servers/networking or desktop infrastructure in a professional environment. It may be on topic for askubuntu but please search their site for similar questions that may already have the answer you're looking for. Mar 28, 2013 at 8:23
  • 1
    Agreed on the off-topic part. Also, you should google for how to set your EDITOR environment variable to an editor you understand how to use. (Hint: currently it's ed; you probably want something else.)
    – Jenny D
    Mar 28, 2013 at 8:25
  • I don't understand why this was migrated away from Sf. Don't sysadmins have to deal with cron and editors and the like ?
    – user591
    Mar 28, 2013 at 15:02

2 Answers 2

3

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.

888
*/1 * * * * php /var/www/cronjob/cronjob_refresh.php
?
^Z
[1]+  Stopped                 crontab -e

You should set your editor preference before running crontab -e

export EDITOR=vi or export 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.

1
  • Hah, somehow your editor has been set to 'ed'. Run select-editor to change that :) Mar 28, 2013 at 11:29
0

First of all, You cannot schedule a every-second cronjob. Because in cron the minimum unit you can specify is minute. What you want is probably to run a script something like:

note: remove one of the 2 backticks after location. The editor wont let me remove them...

#!/usr/bin/perl -w

while(1){

`php /path/to/script/cronjjob_refresh.php``;

sleep(30);

}

But you have to rethink about this, if you need to run a script every 30 seconds on your system you're doing probably something wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy