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:
This will create the binary 'pagerank.checksum'.Code:gcc -o pagerank.checksum pagerank.checksum.c
Test it out by typing:
You should see something like:Code:./pagerank.checksum google.com
Ok, now, create a new file named 'pagerank.sh' and enter the following into it:Code:[root@iqb62 bin]# ./pagerank.checksum google.com Checksum=783326521420
#!/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:
Ok, now - lets set it up to run from cron and email you the results!Code:./pagerank.sh google.com
Create a file named 'pages.to.check.txt' in /usr/local/bin and line by line enter the domains to check:
Create another file in /usr/local/bin/ called 'check_pageranks.sh' and put this into it:Code:www.linuxhostingtalk.com www.google.com www.yahoo.com www.linux.org
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..
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 :)Code:00 6,12,18 * * * /usr/local/bin/check_pageranks.sh >/dev/null 2>&1




Reply With Quote





Bookmarks