I've spent a few hours learning about cron jobs and how they work. I am able to activate and run a cron job, however, I have no idea what commands to use INSIDE the cron file.

I initially wrote a PHP script and tried to activate it with the cron... that didn't work very well 😛

Can anyone tell me where I can find a resource that will allow me to convert my PHP commands into something the cron file can interpret.

    I think you're missunderstanding what the cron daemon actually does. It does not interpret the files you put in it it just runs commands as if they where on the command line. So, for example let's say I have a php script called test.php which I want to run every third day at 6.30am. I would put the following entry into my crontab

    30 6 */3 * * php -q /path/to/test.php > /path/to/test.out
    

    I have chosen to feed the output into the test.out file so that it doesn't get mailed to the crontab's user. As a rule, scripts in the crontab shouldn't give output except for logging information.
    HTH
    Bubblenut

      I guess I thought I had to actually write code in the cron file because when I set one up through cPanel, I got the following error:

      /home/user/public_html/24cronScript.php: line 1: ?php: No such file or directory

      /home/user/public_html/24cronScript.php: line 2: /aquota.user: Permission denied

      /home/user/public_html/24cronScript.php: line 3: //: is a directory

      /home/digitech/public_html/24cronScript.php: line 4: syntax error near unexpected token `('

      /home/user/public_html/24cronScript.php: line 4: `$conn = mysql_connect('localhost',user','password');'

      When I run the PHP script by itself, it works perfectly. Any suggestions?

        Never used cPanel I'm afraid. I can tell you how to add items to your crontab manually though.
        at the shell type crontab -e (-e for edit) add your cron line, which will be something like the one I provided above (see info on crontab).

          From the error messages I'm guessing (never used cPanel either, myself) that cwheeler was putting the PHP script into whatever it is on cPanel you put the cron job command into; instead of saving the script as a file and writing a command to get PHP to call it.

            cPanel only lets you choose what script you want to run and the time intervals you want it to run at...

            I have no idea how/why it is reading the file that way.

              So it turns out I had to create ANOTHER file (that I named cron.txt) and contains the following script:

              lynx -dump 'http://www.mywebsite.com/cronFile.php' > /dev/null

              After I directed the cronjob to read this file, it then loaded my script (in cronFile.php) and ran properly. Thank you for your help and hopefully the next person to have similar problems will find this useful.

                Write a Reply...