albin
albin

Reputation: 3

Run php script with cronjob

so this is my cronjob

PATH=/package/host/localhost/php-5.4.7-1/bin:/bin:/usr/bin
PHPRC=/home/stuff/etc
* * * * * php /home/stuff/private/xFEklnTekl/cmd.php

and this is the cmd.php file

<?php
$c = file("c.txt");
$f = fopen("c.txt", "w+");
$g = $c[0]+1;
fwrite($f, $g);
fclose($f);
?>

Sadly it doesn't update the c.txt file as it should. I think something is wrong with the given path in the php script. I've already tried just /c.txt but it didn't work either. So, what might be wrong?

Upvotes: 0

Views: 462

Answers (1)

fedorqui
fedorqui

Reputation: 289525

Your crontab shouldn't contain anything apart from cronjobs. Try using this:

* * * * * /bin/php /home/stuff/private/xFEklnTekl/cmd.php

And be sure you have +x permissions to execute, as well as crontab user has access to the directory.

Also, put full paths in

$c = file("c.txt");
$f = fopen("c.txt", "w+");

to

$c = file("/home/stuff/private/xFEklnTekl/c.txt");
$f = fopen("/home/stuff/private/xFEklnTekl/c.txt", "w+");

Edit As seen on the comments, instead of /bin/php you have to use whatever comes from which php. In your case,

* * * * * /package/host/localhost/php-5.4.4/bin/php  /home/stuff/private/xFEklnTekl/cmd.php

Upvotes: 1

Related Questions