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.

Cron::edit_line and "bad minute"

Discussion in 'cPanel Developers' started by Echelon17, Mar 7, 2011.

  1. Echelon17

    Echelon17 Well-Known Member

    Joined:
    May 21, 2006
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    Query URL being generated:

    http://xx.xx.xx.xx:2086/xml-api/cpa...el_xmlapi_func=edit_line&command=/usr/bin/php /home/path/to/script > /dev/null&day=*&hour=*&linekey=687e5a83695ba3eabaa2e29ace490b6d&minute=*/15&month=*&weekday=*

    This always returns the following error:

    [linekey] => 263470a91ddc5550c627fdd05ba2bfcd
    [status] => 0
    [statusmsg] => "-":1: bad minute
    errors in crontab file, can't install.

    Any ideas?
     
  2. Echelon17

    Echelon17 Well-Known Member

    Joined:
    May 21, 2006
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    OK, on further investigation using the Dumper tool, it seems that if the "command" contains a space it drops the rest of the argument(s). Any solution to this?
     
  3. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I don't want to sound silly, but did you try encoding you URL query values?
    Code:
    command=/usr/bin/php+/home/path/to/script+>/dev/null
    
    or
    
    command=%2Fusr%2Fbin%2Fphp+%2Fhome%2Fpath%2Fto%2Fscript+%3E+%2Fdev%2Fnull
    
    Other than that, I noticed that your posted query URL is lacking "cpanel_xmlapi_apiversion=2" which is required for making API2 calls via XML-API. Additionally, I'd suggest using "cpanel_xmlapi_user" instead of just "user". This is not manditory, however you'll find problems if you call a function, say Ftp:addftp, where an input parameter key is "user". The result would be mangling of the first user/value pair. So, we have "cpanel_xmlapi_user" to clarify.

    Best Regards,
    -DavidN
     
  4. Echelon17

    Echelon17 Well-Known Member

    Joined:
    May 21, 2006
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    Yep, I tried that, still no luck.

    Are you inferring I should add "+" in place of spaces for the command part of the API call?

    The API documentation says it defaults to version 2, and the error response back is indicating it's using version 2, hence I haven't added this.

    Makes sense, will update my scripts with that, thanks :)
     
  5. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I tried it out on 11.28.83 and it appears to work fine for me.

    Below is my output from the list/add/list/edit/list command. Following that is my test scripts (which use the XML-API PHP client class)

    Code:
    [David-Pro:] $ php -f cron_listcron.php; php -f cron_add_line.php; php -f cron_listcron.php; php -f cron_edit_line.php; php -f cron_listcron.php 
    URL: https://10.1.1.1:2087/xml-api/cpanel
    DATA: cpanel_xmlapi_user=dave&cpanel_xmlapi_module=Cron&cpanel_xmlapi_func=listcron&cpanel_xmlapi_apiversion=2
    Authentication Header: Authorization: Basic -hashed-
    
    
    RESPONSE:
     <?xml version="1.0" ?>
      <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <count>1</count>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>listcron</func>
        <module>Cron</module>
      </cpanelresult>
    
    SimpleXML var_dump:
    SimpleXMLElement Object
    (
        [apiversion] => 2
        [data] => SimpleXMLElement Object
            (
                [count] => 1
            )
    
        [event] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [func] => listcron
        [module] => Cron
    )
    
    URL: https://10.1.1.1:2087/xml-api/cpanel
    DATA: command=%2Fbin%2Fls+%2Fhome%2Fdave+%3E%3E+%2Ftmp%2Fls.log&day=%2A&hour=10&minute=00&month=%2A&weekday=%2A&cpanel_xmlapi_user=dave&cpanel_xmlapi_module=Cron&cpanel_xmlapi_func=add_line&cpanel_xmlapi_apiversion=2
    Authentication Header: Authorization: Basic -hashed-
    
    
    RESPONSE:
     <?xml version="1.0" ?>
      <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <linekey>37df09d7a25ba2dd756b757944a05865</linekey>
          <status>1</status>
          <statusmsg>crontab installed</statusmsg>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>add_line</func>
        <module>Cron</module>
      </cpanelresult>
    
    SimpleXML var_dump:
    SimpleXMLElement Object
    (
        [apiversion] => 2
        [data] => SimpleXMLElement Object
            (
                [linekey] => 37df09d7a25ba2dd756b757944a05865
                [status] => 1
                [statusmsg] => crontab installed
            )
    
        [event] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [func] => add_line
        [module] => Cron
    )
    
    URL: https://10.1.1.1:2087/xml-api/cpanel
    DATA: cpanel_xmlapi_user=dave&cpanel_xmlapi_module=Cron&cpanel_xmlapi_func=listcron&cpanel_xmlapi_apiversion=2
    Authentication Header: Authorization: Basic -hashed-
    
    
    RESPONSE:
     <?xml version="1.0" ?>
      <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <command>/bin/ls /home/dave &gt;&gt; /tmp/ls.log</command>
          <command_htmlsafe>/bin/ls /home/dave &amp;gt;&amp;gt; /tmp/ls.log</command_htmlsafe>
          <count>1</count>
          <day>*</day>
          <hour>10</hour>
          <linekey>37df09d7a25ba2dd756b757944a05865</linekey>
          <minute>00</minute>
          <month>*</month>
          <weekday>*</weekday>
        </data>
        <data>
          <count>2</count>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>listcron</func>
        <module>Cron</module>
      </cpanelresult>
    
    SimpleXML var_dump:
    SimpleXMLElement Object
    (
        [apiversion] => 2
        [data] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [command] => /bin/ls /home/dave >> /tmp/ls.log
                        [command_htmlsafe] => /bin/ls /home/dave &gt;&gt; /tmp/ls.log
                        [count] => 1
                        [day] => *
                        [hour] => 10
                        [linekey] => 37df09d7a25ba2dd756b757944a05865
                        [minute] => 00
                        [month] => *
                        [weekday] => *
                    )
    
                [1] => SimpleXMLElement Object
                    (
                        [count] => 2
                    )
    
            )
    
        [event] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [func] => listcron
        [module] => Cron
    )
    
    URL: https://10.1.1.1:2087/xml-api/cpanel
    DATA: linekey=37df09d7a25ba2dd756b757944a05865&command=%2Fbin%2Fls+%2Fhome%2Fdave+%3E%3E+%2Ftmp%2Fls.log&day=%2A&hour=10&minute=%2A%2F15&month=%2A&weekday=%2A&cpanel_xmlapi_user=dave&cpanel_xmlapi_module=Cron&cpanel_xmlapi_func=edit_line&cpanel_xmlapi_apiversion=2
    Authentication Header: Authorization: Basic -hashed-
    
    
    RESPONSE:
     <?xml version="1.0" ?>
      <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <linekey>32fbf9c75996d20e2628ef8b6018e189</linekey>
          <status>1</status>
          <statusmsg>crontab installed</statusmsg>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>edit_line</func>
        <module>Cron</module>
      </cpanelresult>
    
    SimpleXML var_dump:
    SimpleXMLElement Object
    (
        [apiversion] => 2
        [data] => SimpleXMLElement Object
            (
                [linekey] => 32fbf9c75996d20e2628ef8b6018e189
                [status] => 1
                [statusmsg] => crontab installed
            )
    
        [event] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [func] => edit_line
        [module] => Cron
    )
    
    URL: https://10.1.1.1:2087/xml-api/cpanel
    DATA: cpanel_xmlapi_user=dave&cpanel_xmlapi_module=Cron&cpanel_xmlapi_func=listcron&cpanel_xmlapi_apiversion=2
    Authentication Header: Authorization: Basic -hashed-
    
    
    RESPONSE:
     <?xml version="1.0" ?>
      <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <command>/bin/ls /home/dave &gt;&gt; /tmp/ls.log</command>
          <command_htmlsafe>/bin/ls /home/dave &amp;gt;&amp;gt; /tmp/ls.log</command_htmlsafe>
          <count>1</count>
          <day>*</day>
          <hour>10</hour>
          <linekey>32fbf9c75996d20e2628ef8b6018e189</linekey>
          <minute>*/15</minute>
          <month>*</month>
          <weekday>*</weekday>
        </data>
        <data>
          <count>2</count>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>listcron</func>
        <module>Cron</module>
      </cpanelresult>
    
    SimpleXML var_dump:
    SimpleXMLElement Object
    (
        [apiversion] => 2
        [data] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [command] => /bin/ls /home/dave >> /tmp/ls.log
                        [command_htmlsafe] => /bin/ls /home/dave &gt;&gt; /tmp/ls.log
                        [count] => 1
                        [day] => *
                        [hour] => 10
                        [linekey] => 32fbf9c75996d20e2628ef8b6018e189
                        [minute] => */15
                        [month] => *
                        [weekday] => *
                    )
    
                [1] => SimpleXMLElement Object
                    (
                        [count] => 2
                    )
    
            )
    
        [event] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [func] => listcron
        [module] => Cron
    )
    
    [David-Pro:] $
    
    # cron_listcron.php
    PHP:
    <?php
    include("xmlapi.php");

    $ip "10.1.1.1";
    $root_pass "s3cr3t!";
    $cpuser 'dave';


    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);

    $xmlapi->set_debug(1);

    $m 'Cron';
    $f 'listcron';
    $args = array();

    $xmlapi->api2_query($cpuser$m$f$args);
    ?>
    # cron_add_line.php
    PHP:
    <?php
    include("xmlapi.php");

    $ip "10.1.1.1";
    $root_pass "s3cr3t!";
    $cpuser 'dave';


    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);

    $xmlapi->set_debug(1);

    $m 'Cron';
    $f 'add_line';
    $args = array(
        
    'command' => '/bin/ls /home/dave >> /tmp/ls.log',
        
    'day'      => '*',
        
    'hour'      => '10',
        
    'minute'  => '00',
        
    'month'      => '*',
        
    'weekday' => '*',
    );

    $xmlapi->api2_query($cpuser$m$f$args);
    ?>
    # cron_edit_line.php
    PHP:
    <?php
    include("xmlapi.php");

    $ip "10.1.1.1";
    $root_pass "s3cr3t!";
    $cpuser 'dave';


    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);

    $xmlapi->set_debug(1);

    $m 'Cron';
    $f 'edit_line';
    $args = array(
        
    'linekey' => '37df09d7a25ba2dd756b757944a05865',
        
    'command' => '/bin/ls /home/dave >> /tmp/ls.log',
        
    'day'      => '*',
        
    'hour'      => '10',
        
    'minute'  => '*/15',
        
    'month'      => '*',
        
    'weekday' => '*',
    );

    $xmlapi->api2_query($cpuser$m$f$args);
    ?>
    And to clarify, about the pluses (+), I was simply referring to general url parameter encoding, nothing crazy ;)

    Your absolutely right about the default behave of the XML-API query parsing. If it notices that it is a cPanel API tag and the request does not contain the 'cpanel_xmlapi_apiversion' key/value pair, it will assume API2. I just prefer to be explicit. It's up to you :)

    Best Regards,
    -DavidN
     
  6. Echelon17

    Echelon17 Well-Known Member

    Joined:
    May 21, 2006
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    David,

    Why reinvent the wheel when I can use your XMLAPI class huh? :)

    I modified my code to workaround your class, and everything is working great now. Thank you very much for your assistance.
     
Loading...
Similar Threads - Cron edit_line bad
  1. mesut85u2
    Replies:
    14
    Views:
    1,319

Share This Page