SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    setting up a crontask

    I followed this tutorial to backup my site vie a crontask in cpanel,
    http://www.v-nessa.net/2007/01/03/cp...-backup-script
    I thought everything was set up correctly, but get an email every night which says



    Failed to open socket connection... Bailing out!


    Heres the php script
    PHP Code:
    <?php

    // PHP script to allow periodic cPanel backups automatically.
    // v-nessa.net
    // Permissions on this file should be 600 
    // Place outside your public_html
    // Crontab:  30 3 * * * /usr/local/bin/php /home/username/cpanel_backup.php

    // ********* Configuration *********

    // Info required for cPanel access
    $cpuser "xxxxxx"// Username used to login to CPanel
    $cppass "xxxxxx"// Password used to login to CPanel
    $domain "www.xxxxxx.com/"// Domain name where CPanel is run
    $skin "x3"// Set to cPanel skin you use (script won't work if it doesn't match)

    // Info required for FTP host
    $ftpuser "xxxxxxx"// Username for FTP account
    $ftppass "xxxxxxx"// Password for FTP account
    $ftphost "www.xxxxxxxx.com"// Full hostname or IP address for FTP host
    $ftpmode "passiveftp"// FTP mode ("ftp" for active, "passiveftp" for passive)
    $ftpport "21"// FTP port, usually 21
    $ftpdir "/backups"// Path to folder where backups should be stored off of FTP root. Folder must exist.

    // Notification information
    $notifyemail "xxxxx@gmail.com"// Email address to send results

    // Secure or non-secure mode
    $secure 0// Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP

    // Set to 1 to have web page result appear in your cron log
    $debug 1;

    // *********** Don't Touch!! *********

    if ($secure) {
       
    $url "ssl://".$domain;
       
    $port 2083;
    } else {
       
    $url $domain;
       
    $port 2082;
    }

    $socket fsockopen($url,$port);
    if (!
    $socket) { echo "Failed to open socket connection... Bailing out!\n"; exit; }

    // Encode authentication string
    $authstr $cpuser.":".$cppass;
    $pass base64_encode($authstr);

    $params "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftpdir&submit=Generate Backup";

    // Make POST to cPanel
    fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");
    fputs($socket,"Host: $domain\r\n");
    fputs($socket,"Authorization: Basic $pass\r\n");
    fputs($socket,"Connection: Close\r\n");
    fputs($socket,"\r\n");

    // Grab response even if we don't do anything with it.
    while (!feof($socket)) {
      
    $response fgets($socket,4096);
      if (
    $debug) echo $response;
    }

    fclose($socket);

    ?>
    Last edited by ScallioXTX; Oct 18, 2013 at 17:32. Reason: Keep private information private!
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,070
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Try to change this:

    PHP Code:
    $socket fsockopen($url,$port);
    if (!
    $socket) { echo "Failed to open socket connection... Bailing out!\n"; exit; } 
    to this

    PHP Code:
    $socket fsockopen($url$port$errNo$errStr);
    if (!
    $socket) { echo "Failed to open socket connection ({$errStr}{$errNo}) ... Bailing out!\n"; exit; } 
    run it again, and see what the output is. It should give you the reason it's unable to connect.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    im getting


    Failed to open socket connection (php_network_getaddresses: getaddrinfo failed: Name or service not known, 0) ... Bailing out!

    what does that even mean?
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,070
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    It means the server can't resolve the hostname of the server you want it to connect to. Are you you entered the host name (domain name) correctly?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I was kind of confused there, so I guess I was wrong,
    PHP Code:
    $domain "www.swedishsweetsandimports.com/"// Domain name where CPanel is run
    ...
    ...
    $ftphost "www.swedishsweetsandimports.com"// Full hostname or IP address for FTP host 
    Isn';t that the domain, cause the sites at
    that URL (http://www.swedishsweetsandimports.com/)
    but the address I use to get to cpanel is
    https://server73.web-hosting.com:208.../x3/index.html
    "Oh, and Jenkins--apparently your mother died this morning."

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,070
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    You need to change $domain to the domain cPanel is run on (server73.web-hosting.com, WITHOUT the :2083! ). Also set $secure = 1
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    thanks
    "Oh, and Jenkins--apparently your mother died this morning."

  8. #8
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    guess it didnm't work, cause heres the email,

    Failed to open socket connection (php_network_getaddresses: getaddrinfo failed: No address associated with hostname, 0) ... Bailing out!

    The hostname I use for FTP is
    swedishsweetsandimports.com
    so
    PHP Code:
    $ftphost "swedishsweetsandimports.com"// Full hostname or IP address for FTP host 
    is right?
    "Oh, and Jenkins--apparently your mother died this morning."

  9. #9
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,070
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Looks fine to me. If were you I'd contact the hoster to ask them why PHP doesn't seem to be able to connect to that host. It sounds like a DNS error if you ask me.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •