Welcome to the Linux Hosting Talk.
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2011
    Location
    Dublin, PA
    Posts
    1,138
    Rep Power
    10

    Check pagerank with your linux shell and cron and get email updates!

    I set this up on one of my servers recently and love it. I get emails every 6 hours (6am, 12pm, 6pm, 12am) with pagerank results for all of my sites on the list..

    First, download the pagerank script created by http://zhiwei.li/
    (its below - their site was broken at the time of this writing)

    /******************************************************************************
    * Filename : pagerank.c
    * Description : Google PageRank Checksum Algorithm
    * Author : [url]http://zhiwei.li/[/url]
    * Log : Ver 0.1 2005-9-13 first release
    * Ver 1.0 2005-10-19 fixed :final character bug
    * Ver 1.1 2006-10-05 refine code
    * Ver 1.2 2008-8-20 use boolean type
    *******************************************************************************/


    #include <stdio.h>
    #include <stdbool.h>


    int ConvertStrToInt(char *pStr, int Init, int Factor)
    {
    while (*pStr) {
    Init *= Factor;
    Init += *pStr++;
    }
    return Init;
    }


    int HashURL(char *pStr)
    {
    unsigned int C1, C2, T1, T2;


    C1 = ConvertStrToInt(pStr, 0x1505, 0x21);
    C2 = ConvertStrToInt(pStr, 0, 0x1003F);
    C1 >>= 2;
    C1 = ((C1 >> 4) & 0x3FFFFC0) | (C1 & 0x3F);
    C1 = ((C1 >> 4) & 0x3FFC00) | (C1 & 0x3FF);
    C1 = ((C1 >> 4) & 0x3C000) | (C1 & 0x3FFF);


    T1 = (C1 & 0x3C0) << 4;
    T1 |= C1 & 0x3C;
    T1 = (T1 << 2) | (C2 & 0xF0F);


    T2 = (C1 & 0xFFFFC000) << 4;
    T2 |= C1 & 0x3C00;
    T2 = (T2 << 0xA) | (C2 & 0xF0F0000);


    return (T1 | T2);
    }


    char CheckHash(unsigned int HashInt)
    {
    int Check = 0;
    bool Flag = false;
    int Remainder;


    do {
    Remainder = HashInt % 10;
    HashInt /= 10;
    if (Flag){
    Remainder += Remainder;
    Remainder = (Remainder / 10) + (Remainder % 10);
    }
    Check += Remainder;
    Flag = !Flag;
    } while( 0 != HashInt);


    Check %= 10;
    if (0 != Check) {
    Check = 10 - Check;
    if (Flag) {
    if (1 == (Check % 2)) {
    Check += 9;
    }
    Check >>= 1;
    }
    }
    Check += 0x30;
    return Check;
    }


    int main(int argc, char* argv[])
    {
    unsigned int HashInt;


    if (argc != 2) {
    printf("Usage: %s [URL]\n",argv[0]);
    return 1;
    }


    HashInt = HashURL(argv[1]);
    printf("Checksum=7%c%u\n", CheckHash(HashInt), HashInt);
    return 0;
    }


    This is C source code, so save it as 'pagerank.checksum.c' and then compile it by typing:
    Code:
    gcc -o pagerank.checksum pagerank.checksum.c
    This will create the binary 'pagerank.checksum'.

    Test it out by typing:
    Code:
    ./pagerank.checksum google.com
    You should see something like:
    Code:
    [root@iqb62 bin]# ./pagerank.checksum google.com
    Checksum=783326521420
    Ok, now, create a new file named 'pagerank.sh' and enter the following into it:

    #!/bin/bash
    page=$1
    page_encoded=`echo $page | sed 's/\//%2F/g;s/:/%3A/g'`
    checksum=`/usr/local/bin/pagerank.checksum $page | sed 's/Checksum=//'`
    pr_request="http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=$checksum&ie=UTF-8&oe=UTF-8&features=Rank&q=info:$page_encoded"
    curl -s "$pr_request" | cut -d":" -f3


    And test it out like:
    Code:
    ./pagerank.sh google.com
    Ok, now - lets set it up to run from cron and email you the results!

    Create a file named 'pages.to.check.txt' in /usr/local/bin and line by line enter the domains to check:
    Code:
    www.linuxhostingtalk.com
    www.google.com
    www.yahoo.com
    www.linux.org
    Create another file in /usr/local/bin/ called 'check_pageranks.sh' and put this into it:
    Code:
    #!/bin/bash
    /bin/rm -f /usr/local/bin/results
    for URL in `cat /usr/local/bin/pages.to.check.txt`; do echo -e "$URL\t$(/usr/local/bin/pagerank.sh $URL)" >> /usr/local/bin/results; done
    mail -s "Google Page Rank Results" your-email@domain.com < /usr/local/bin/results



    And last but not least, create a cron job for the script to kick off - lets do it at 6am, 12pm and 6pm..
    Code:
    00 6,12,18 * * * /usr/local/bin/check_pageranks.sh >/dev/null 2>&1
    And there you go - now you'll get an email 3 times/day with your pageranks! If you want to do it the old fashioned way, then visit Check-Pagerank.org :)

 

 

Similar Threads

  1. shelr, broadcast your Linux shell on the net
    By Rob in forum Linux Articles
    Replies: 1
    Last Post: 05-13-2012, 04:21 PM
  2. Monitor your bandwidth from the Linux shell
    By Rob in forum Linux Articles
    Replies: 0
    Last Post: 04-15-2012, 08:40 PM
  3. Email on shutdown and restart (Linux)
    By Rob in forum Linux Articles
    Replies: 0
    Last Post: 04-04-2012, 09:03 PM
  4. Search Wikipedia Through CLI (Shell) In Linux
    By Rob in forum Linux Articles
    Replies: 0
    Last Post: 03-27-2012, 09:34 AM
  5. Set up a basic cron job
    By Rob in forum On the Server
    Replies: 0
    Last Post: 08-23-2011, 12:49 PM

Tags for this Thread

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
  •  


» Our Friends

» Recent Threads

Powered by vBadvanced
Back to top