0

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?

3
  • call cmd.php from the command line - any out output? does it work? Commented Feb 10, 2013 at 23:46
  • Maybe the permissions of the text file Commented Feb 10, 2013 at 23:52
  • @Dagon running it from the command line works perfectly. I'm not sure from where the cronjob runs the php file, that's why I don't know form where to point the c.txt file. Commented Feb 10, 2013 at 23:55

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

6 Comments

I just got a mail saying /bin/sh: bin/php: No such file or directory, did and checked everything else and it's still not working. Thanks tho!
The command you put in crontab should work itself. So you firstly make sure it works and then put it in crontab. To know the route of php, type which php. It will be something like /bin/php, /usr/bin/php, etc. This is the route you will have to use to execute your script.
Thanks! * * * * * /package/host/localhost/php-5.4.4/bin/php /home/albin/private/xFEklnTekl/cmd.php worked perfectly!
Great! I edit my answer to include our comments : ) Mark the question as answered if now everything is working!
Done! Just another question about cronjobs and php. Will this cronjob run the file just as I would do it manually with the console like "php -f file.php" or will the cronjob execute something like a cURL request? My "real" cmd.php file needs to run for about 2 hours (sleep() function).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.