954,228 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Crone job in Ubuntu 8

Hi,

I have ubuntu 8 and want to set a crone job.

When ubuntu starts, i login as;
username: ubuntu
password: ubuntu

I open terminal an type these:

root@ubuntu:/home/ubuntu# crontab -e
*/10 * * * * /var/www/project/index.php

(to run index.php every 10 seconds) and save it and wait.

Nothing happens!!!

Do i miss anything? Do you think root@ubuntu:/home/ubuntu# is wrong?

Note : In the System>Administration>Users and Groups, there are "ubuntu" and "root" as users. Nothing else. Also, by the clock top right end side, it says "ubuntu".

Thanks

veledrom
Master Poster
754 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

do you have permission to run that file? also, since its a php script, it should be run from the apache+php, not straight as a command line

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

I can run it on Firefox (localhost/test/index.php). I change permission to root and try OR permission to ubuntu and try. Both doesn't work. This is exactly what i do.

I login to ubuntu as : username= ubuntu password= ubuntu and "ubuntu user" is shown next to clock, top right end side.

root@ubuntu:home/ubuntu# sudo gedit /var/www/test/index.php

<?php
$conn=mysql_connect("localhost", "root", "");
if (!$conn) {
    echo "err";
} else {
    mysql_select_db("mydb", $conn);

    $sql="insert into login (username, moment) values ('uuu', now())";
    $run=mysql_query($sql);
}
?>
root@ubuntu:home/ubuntu# cron -e -u ubuntu
1 * * * * /var/www/test/index.php
root@ubuntu:home/ubuntu# cron -e
1 * * * * /var/www/test/index.php

root@ubuntu:home/ubuntu# ls -l /var/spool/cron/crontabs
-rw ---------- 1 root crontab 264 2009-03-15 13:58 root
-rw ---------- 1 root ubuntu 242 2009-03-15 13:58 root~
-rw ---------- 1 ubuntu crontab 264 2009-03-15 13:58 ubuntu
veledrom
Master Poster
754 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

why don't you do the same in bash/perl/python ?

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

SOLVED.

I tried to run php on the terminal. It didn't run because php5-cli wasn't installed. I have installed and changed cron to */1 * * * * /usr/bin/php /var/www/test/index.php run every 1 minute.

It works now. thanks

veledrom
Master Poster
754 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: