3

I need to send emails hourly and daily. I've tried nearly everything but it appears my crontab just won't work. If I run the scripts via a browser e.g

http://localhost/Maisha/Functions/sendhourlymails.php  

my emails get sent beautifully.(I moved default website localhost to public_html.) I don't know whats wrong. I read some post in stack overflow including the executable path of php helps hence I've put the /usr/bin/php before the actual script to be cronned will work but it does not. Removing /usr/bin/php does not work. Adding php before the actual script isn't working. I have the following entries in my crontab.

# m h  dom mon dow   command
0  *  *   *   *    /usr/bin/php /home/maxwell/public_html/Maisha/Functions/sendhourlymails.php
0  0  *   *   *    /usr/bin/php /home/maxwell/public_html/Maisha/Functions/senddailymails.php
5
  • 1
    What happens if you run the command directly on the command line? Commented Feb 27, 2011 at 15:36
  • What happens when you run the commands manually on the command line? Commented Feb 27, 2011 at 15:36
  • have you looked for errors in the logs? Commented Feb 27, 2011 at 15:36
  • @Alister how do I do that? I'm a Newbie in linux environment Commented Feb 27, 2011 at 17:19
  • @Eineki How do I do that and which error logs? Commented Feb 27, 2011 at 17:22

3 Answers 3

6

Try to call the script via http with wget like so:

* * * * * wget http://localhost/myscript >/dev/null 2>&1
Sign up to request clarification or add additional context in comments.

3 Comments

Do I put that in my crontab entries or wget is different?
wget is a unix utility like any other and cron executes whatever command (with limitations) you want.
By the way it is best if this is done as su i.e create this cron as super user.
0

Yeh, wget is good option, also you can try to use:

0 * * * * /usr/sbin/php /usr/bin/php /home/maxwell/public_html/Maisha/Functions/sendhourlymails.php

but it could work wrong due to relative paths.

Also you should look at http://php.net/manual/en/features.commandline.php

1 Comment

usr/sbin/php does not exist for my case.
0

Try to put this into your .php file

<?php
    #!/usr/local/bin/php -q
//your code here
?>

Then if you include any file into this file you must use something like:

include"/var/www/../your_absolute_path_from_root_folder/connect.php";

Finnaly make sure this file has the right permissions..Try

chmod 755 /var/www/.../file.php

Then if you edit your crontab file with the following command

vi /etc/crontab

put something like

10 6 * * * root php /var/www/..path../file.php

and restart the service with this command

/etc/init.d/cron restart

you have do your job!!

  • Note-Tip:the php file isn't neccessery to be into public_html folder!!

Comments

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.