Results 1 to 7 of 7

Thread: How can I modify cron job run time using php.

  1. #1
    Join Date
    Dec 2008
    Beans
    33

    How can I modify cron job run time using php.

    I have a web cam facing a view which has spectacular sunsets and sunrises. I want to grab a picture, at, say 20 minutes before sunset and 15 mins after after sunrise each day. I can use php/cURL to grab a picture from the camera, give it a name/date/timestamp and save it.

    I can use php to get the sunset/rise times for my lat/long into variables, and can write a .txt file in the 'right' format that will overwrite the previous day's file/times with the new ones, but can't work out how (and where) to save the file so that it runs.

    Every 'help' page I read says something like 'compose your cron file using crontab and your favourite editor'. I know that using crontab checks the syntax before saving, but assuming I have the right syntax can I just write my revised file to a specific location and avoid using the crontab/editor route?

    My hosting company lets me write files using suphp if that makes any difference.

    Thanks for your help.

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,664
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: How can I modify cron job run time using php.

    Editing the crontab feels like a bit of a hack, even if it works. Could you use 'at' to schedule these jobs? Maybe have a cron job that runs at midnight and schedules the sunrise/sunset jobs for that day? That's what 'at' is for really - irregular scheduled jobs.

    I note you have limited access to the machine and this might not be possible. Just a suggestion.

  3. #3
    Join Date
    Sep 2006
    Beans
    7,624
    Distro
    Lubuntu Development Release

    at

    +1 for at

  4. #4
    Join Date
    Dec 2008
    Beans
    33

    Re: How can I modify cron job run time using php.

    Thanks folks..

    I've read the at man page: http://manpages.ubuntu.com/manpages/...man1/at.1.html

    And am not sure how I would use it. I can see that it appears to run a single task at some point in the future, but can't see how to get the data into it from my PHP.

    The flow I think is something like this:

    1.Schedule daily cronjob which:

    2. Runs my php script, which gets the sun up/down times and adds/deletes my time offsets to these.

    3. Using at, for those times run my php grab a picture script.

    I'm lost between 2 and 3,

    Any help on using php to set up an at event would be welcome.

    I'm reading the php man page on exec(), which could, I think, be used in a daily crontab job to run the command 'at' with the required times and actions. Thinking and reading about the shared server problems, I have apache set up on my home network, so will try to get it running locally first, and if it works try the external hosted server.

    I would still appreciate any advice!

    Thanks,



    Thank you
    Last edited by colinmccubbin; February 7th, 2012 at 04:09 PM. Reason: Added ref to exec()

  5. #5
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    9,033
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: How can I modify cron job run time using php.

    I run PHP scripts from crontab. You need to make sure you have installed the php-cli package, then create a crontab entry like this:

    Code:
    */10 * * * * /usr/bin/php /path/to/camera_script.php
    This invokes your script every ten minutes. The script can then check if the current time is within the window for a sunrise/sunset picture and act accordingly.

  6. #6
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,664
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: How can I modify cron job run time using php.

    Good, simple solution. =D>

  7. #7
    Join Date
    Dec 2008
    Beans
    33

    Re: How can I modify cron job run time using php.

    A quick check shows that I have php5-cli installed, so I will give it a try! Many thanks indeed.

    Colin

    Quote Originally Posted by SeijiSensei View Post
    I run PHP scripts from crontab. You need to make sure you have installed the php-cli package, then create a crontab entry like this:

    Code:
    */10 * * * * /usr/bin/php /path/to/camera_script.php
    This invokes your script every ten minutes. The script can then check if the current time is within the window for a sunrise/sunset picture and act accordingly.

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
  •