SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Automate Script to run every day

    I have a script which opens a .zip file and updates a database with its contents. The .zip file is sent to my server eveyday around the same time. All I have to do is click two buttons to get the process to run which is fine. The only problem is when I'm not there to click the buttons the data in the database end up not being entirely accurate.

    Is there a way I can get the scripts I need to run automatically every day?

    I had thought that perhaps Cronjobs was the way to do this but I don't know where to start to set this up.

    If anyone has any ideas or can tell me how to set up Cronjobs to do this I'd appreciate the help.

    Thanks in advance

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you have to have SSH access for Cronjob,
    http://unixgeeks.org/security/newbie/unix/cron-1.html

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SSH not needed. Do you have cPanel? Cron or CronTab is one of the icons in cPanel.

    I don't remember how to run a PHP script from cron, but I recall that there are at least two different ways, and at least one of them doesn't work at all hosts. If in doubt, ask your host what is the correct way.

  4. #4
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah if you have CPanel, or really any other control panel, it should be an option in there.

    If not, the cron should look something like:

    Code:
    0 0 * * * /home/username/script.php
    That assumes you want to run it at 12:00 AM.

    To run it, you can make your script executable, and include the path to the PHP executable at the top like:

    Code:
    #!/usr/local/bin/php
    Or, you can change your cron command to call PHP directly:

    Code:
    0 0 * * * php /home/username/script.php
    or you can use wget if it is in the document root.

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's three ways to do it!

    Some hosts disable wget to prevent it being misused by malicious scripts from the outside.

    If you have little experience with Cron, as I do, you will probably find the "Standard" option easier to understand than the "Advanced (Unix style)". (You'll see those as options.) In Standard, select an option in every time specifier so that together they define the recurrence you want.

    For your task, you'd select an hour and minute (not any of the "Every" options) plus "Every Month", "Every Day", and, I guess, "Every Weekday" (even though it would seem to overlap "Every Day").

    The command to run would be, for devbanana's third example: php /home/username/script.php

    In addition to whatever action the script takes, output from the cron job, including any error messages, will be sent to the email address you enter in the box on the Cron page.

  6. #6
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi

    I've not got cpanel unfortunately, its direct admin which I don't think is as user friendly as cpanal but I'm stuck with it.
    I've taken a screen grab of the cron jobs page I've set up.
    Can anyone tell me if this looks like I've set up the cron jobs correctly.
    I want each of these scripts to run at the same time everyday every month for the whole year.
    If I've got this wrong somehow can you tell me what it should be please?



    thanks for any help in advance.
    Attached Images Attached Images


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •