0

I setup a cron job (in Virtualmin based of Webmin) for execute a simple test script and it work well.

The cron command used is:

/usr/bin/php -q /home/myuser/domains/mysite.com/public_html/mailtest.php

The url is:

www.mysite.com/mailtest.php

The content of "mailtest.php" is:

<?php
$to = "your@mail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "any@any.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Now I tried to execute another script and I have of course modify path and file name who is simply:

/usr/bin/php -q /home/myuser/domains/mysite.com/public_html/myfolder/myscript.php

But here I don't know why my script is not executed. When I go to his related url "www.mysite.com/myfolder/myscript.php" the script is well executed.

The content of "myscript.php" is:

<?php
require_once(dirname(__FILE__).'/includes/includes.php');

$mails = POP3Mailer::ProcessMails();
require_once($BASE_PATH.'/includes/footer.php');
?>

Somebody have an idea why the cron won't fire with "myscript.php" ???

Thank for your time

dotcom22
  • 249
  • 1
  • 7
  • 19
  • Well I solved my problem. It was related to "myscript.ph" who had some code incompatible. I did not know it was possible... Anyway thank to Romain Braun and 5k7 for trying to help. Cheers – dotcom22 Mar 15 '13 at 14:06

2 Answers2

0

I'm not really sure about it. But maybe you should check permissions on this file.

Use the chmod command.

Romain Braun
  • 3,624
  • 4
  • 23
  • 46
0

Cron is working in very basic environment. Create new file. Make it executable (chmod +x) and add it to cron. Add #!/bin/bash at the begining of the file and than your script via /usr/local/bin/php.

Your file should look like :

#!/bin/bash
/usr/local/bin/php /url/to/your/script.php
5k7
  • 107
  • 1
  • 9