Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Dennis Kaarsemaker Mar 28 '13 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 '13 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 ? –  Iain Mar 28 '13 at 15:02
add comment

migrated from serverfault.com Mar 28 '13 at 14:52

This question came from our site for professional system and network administrators.

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
Hah, somehow your editor has been set to 'ed'. Run select-editor to change that :) –  Dennis Kaarsemaker Mar 28 '13 at 11:29
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.