1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

IF... ELSE... on Cron Job's Syntax

Discussion in 'Apache' started by dropdrop, Nov 13, 2011.

  1. #1
    Hello DP'ers,

    I want to do something like this:

    I listed more than 10K of data on the database every day, then I will run the cron with duration each at 00:00 every day to check one by one from the data. But I was afraid when at 00:00 the following day the data has not been completed on all checks.

    So I want to create logic in the cpanel cron command as follows:

    The next question, is it possible a PHP file that is run by cron on doing the cron command to turn off when the data was completed in check all (eg the data is complete when the hours of 10:00)? then when at 00:00 cron will run again by the server. Or ... whether when the cron job has been completed to check the data, the "cron job" will automatically stop and will work again when at 00:00 again?

    I really hope help to do this in cron syntax in cpanel, thanks in advance.
     
    dropdrop, Nov 13, 2011 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    I don't think you can do this from cron command line, but you could do it with a simple script modification.

    My suggestion for solution:

    Step 1. In your script that performs that task every day, at the beginning insert one quick check for some file, for example let's call it task.lock file. If the file exists, then your script exits and doesn't do anything, if the file doesn't exist then your script continues.
    Step 2. After checking first step, and the script continued, script creates the file called task.lock (so if script tries again to run at any time it will exit in the step 1 because task.lock exists)
    Step 3. Continue with your regular script execution, and run the code you currently have
    Step 4. When the script finishes work, delete the file task.lock (which will allow the next script instance to pass the step 1 and do the work again)

    The cronjob command line with this method would be the regular one for executing php script.

    You could even run the cron more often with this method as the script will just exit if the previous instance has not yet finished.

    Note: Make sure to use the full directory path to your lock file when running the script from cron.
     
    pr0t0n, Nov 14, 2011 IP
  3. dropdrop

    dropdrop Active Member

    Messages:
    142
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks for your idea, so the cron still run event the first job still run, right ? if it does not create buildup on the server when the two cron crontab do even more, though no data is executed ?
     
    dropdrop, Nov 14, 2011 IP