#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    17

    running script with crontab


    Im trying to execute a php file with cron that will email me every minute(just for testing), but can't for some reason, these are the 2 crontabs i've tried from some examples but they aren't executing. Any ideas, i've never used cron before, but from what i've read it's not much more complicated than what i have

    crontab:
    * * * * * lynx -dump http://www.abc.com/testcron.php
    or
    * * * * * /usr/local/www/htdocs/testcron.php

    testcron.php:
    PHP Code:
    mail("me@abc.com","test","this is a test"); 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,960
    Rep Power
    194
    where you have asterisks you tell cron when to execute the line. pobably any time, any minute, any second is not valid

    this is the order and meaning of the 5 values and their range (taken from FreeBSDīs man pages):
    minute 0-59
    hour 0-23
    day of month 1-31
    month 1-12 (or names, see below)
    day of week 0-7 (0 or 7 is Sun, or use names)
    also maybe the path is not set, so you need to supply the full path to lynx.
  4. #3
  5. Here, not there
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    312
    Rep Power
    16
    Additionally, with the second attempt
    PHP Code:
    * * * * * /usr/local/www/htdocs/testcron.php 
    you need to make certain that testcron.php is executable from the command line. What happens when you run testcron.php from the commandline? If it doesn't work then you need to read documents such as http://www.devarticles.com/art/1/231
  6. #4
  7. No Profile Picture
    -------------------
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    200
    Rep Power
    18
    * * * * * lynx -dump http://www.abc.com/testcron.php
    What you have listed in your first example is correct. You may, however, need to specify the full path to lynx (the cron daemon may not know where 'lynx' is). From the command line, try 'whereis lynx', and use the output in your crontab:
    * * * * * /usr/local/bin/lynx -dump http://www.abc.com/testcron.php

    And just to make sure that the php page is not the problem, hit your 'testcron' page manually (by using the same command in your teminal window: "/path/to/lynx -dump...") and make sure that you get the mail.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    17
    thanks everyone
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    17
    I've executed both from the command line:
    /usr/local/bin/lynx -dump http://www.abc.com/testcron.php
    and
    lynx -dump http://www.abc.com/testcron.php

    and both executed.

    but using my crontab:
    * * * * * /usr/local/bin/lynx -dump http://www.abc.com/testcron.php
    or
    1 * * * * /usr/local/bin/lynx -dump http://www.abc.com/testcron.php

    neither would execute. I'm stumped
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,960
    Rep Power
    194
    ... btw this is off-topic, this is the php forum. this discussion should be moved to the linux forum (iīll ask the mod, wait...).

    are you using linux? which distribution?

    maybe there is some other problem.
    - did you check if cron is running at all? ("ps ax|grep cron")
    - did you read the logs? (/var/log/cron or /var/log/messages)
  14. #8
  15. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    Well, it's half on topic and can be an issue that people run into when trying to schedule a PHP script to run through cron.

    So you say that those lines work from the command line, but they don't work in cron, right? What are all of the steps you're doing to add this line to your cron? If I remember correctly, there are a couple steps involved to get this going. Or, like someone else said, is cron even running?

    ---John Holmes...
    -- Cigars, whiskey and wild, wild women. --
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    17
    Hi John,
    I login to my server thru telnet do the following command:
    crontab /path/to/my/crontab

    then to check it:
    crontab -l
    this shows me the contents of my crontab

    and as far as testing to see if cron was running, I used
    - did you check if cron is running at all? ("ps ax|grep cron")
    and this was the response:

    70850 ?? IsJ 0:47.73 cron
    71611 p6 S+J 0:00.00 grep cron

    i have no idea if that means yes or no.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,960
    Rep Power
    194
    this means yes, it is running

    did you find the log files? (i looked, mine go to /var/log/cron, but maybe i set this up...)
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    17
    I found and checked the /var/log/cron file and there weren't any entries referring to my crontab. Where would i find errors if there were any trying to run a crontab?
  22. #12
  23. No Profile Picture
    -------------------
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    200
    Rep Power
    18
    This is pretty much off-topic for the PHP list now, but try add this line to your crontab:

    * * * * * date >> /your/home/dir/cron.txt

    (replace /your/home/dir/ with the full path to your home directory)
    Let it run a couple minutes then check if it created a file called 'cron.txt' that has a bunch of dates in it...
  24. #13
  25. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    Yes, it is now.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,960
    Rep Power
    194
    mikeShank, you can find all error messages concerning cron like this:

    grep -iR "cron" /var/log

    (grep: case insensitive, Recursive)
  28. #15
  29. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Uruguay
    Posts
    338
    Rep Power
    17
    tail -f /var/log/cron
    displays the last ten entries in real time

    If you solved your problem please share your solution.
    Thank you
    Last edited by dstonek; December 4th, 2005 at 02:31 PM.

IMN logo majestic logo threadwatch logo seochat tools logo