The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Resolved] Add Auto Cron

Discussion in 'cPanel Developers' started by varunms, Dec 15, 2013.

  1. varunms

    varunms Active Member

    Joined:
    Aug 29, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    INDIA
    cPanel Access Level:
    Root Administrator
    Hi

    i am developing a app for my clients for cpanel.. when a user login to cpanel and click a button which is added by me.. if that button is clicked i need to add a cron in that user's cpanel for eg

    my user name is strt23
    and i am login in to cpanel and clicked add cron in main page after clicking i need to view the cron added in my cpanel cron tab page
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    In order to find the API calls for cron, you'll need to look in /usr/local/cpanel/base/frontend/x3/cron.

    In that directory, we can find cron_entries.html which calls the tag to list cron tasks:

    <?cptt Cron::listcron(cron/cron_entries.tmpl) omit_extra_record=true ?>

    This means that an API1/API2 call is in use. Here's the call in question:

    Cron Module Documentation

    You can't ask for a specific cron entry so you'll have to get a list of all the cron entries and then loop through and find just the one you want and display it.
     
  3. varunms

    varunms Active Member

    Joined:
    Aug 29, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    INDIA
    cPanel Access Level:
    Root Administrator
    Thanks for your reply.. but i just need to add a new corn & if user changes the settings i need to update the same cron using php

     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    To add a cron task, use the add_line API call:

    Cron Module Documentation

    You can use the cPanel PHP API class:

    https://github.com/CpanelInc/xmlapi-php

    Here's an example of making an API2 call:

    https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/api2_example_withargs.php

    So, in order to add the cron task, use Cron::add_line() and then use Cron::list_cron() to get all cron entries. Then loop through and find the line that was previously added and use Cron::edit_line() to edit it:

    Cron Module Documentation
     
Loading...

Share This Page