#!/usr/bin/gawk -f # charities.cron 1.7.0 # (c) Stephen E. Sachs , 05/23/2002 # Released under GNU General Public License, www.gnu.org/copyleft/gpl.html # # This is a cron script in the gawk language to frequent the various # charity sites affiliated with freedonation.com. # # These sites have obtained corporate sponsorship to enable web users to # donate food, health care, and other goods to the needy by clicking on a # link. The sites generally count one click per IP address per # day; while it's hard for people to remember to return to each site each # day to donate, it's a perfect task for a cron job. This script uses # lynx to download the page to a temp file, identify the proper link, # "click" it (sending output to /dev/null), and then remove the temp file. # By making this a daily cron job, you can cause thousands of dollars to # be donated to charity each year. # # If you cannot run your own cron jobs, an alternative is to place the # command "./charities.cron &" in your .bashrc or .login file, so that the # script will execute each time you log in to your shell account and be # counted at least once each day. # # Please remember to change the line at the very beginning of this script # to reflect the location of gawk on your system (type 'which gawk' if # you're not sure), and do the same for lynx below. # # This version brings back support for certain charity sites affiliated # with thehungersite.com which appear to have come back in service. Those # thar remain out of operation are still commented out. Also, as some # users had requested, this version adds a debugging option (which # unfortunately makes for much messier code). Finally, this version # permanently fixes the tempfile bug that had plagued previous versions. # # Use in good health, # Steve BEGIN { # lynx is assumed to be /usr/bin/lynx lynxdump = "TERM=vt100 TMPDIR=/tmp /usr/bin/lynx -dump" debug = "" # uncomment the following line to turn on debugging # debug = "on" dest = "/dev/null"; if (debug) dest = "/dev/stdout" docharity("http://www.thehungersite.com","Give Free Food") docharity("http://www.therainforestsite.com","Click here to help \ preserve our rainforests!") docharity("http://www.thebreastcancersite.com","Provide free mammograms!") # the following are apparently no longer in service: # docharity("http://www.thekidsaidssite.com","Donate Free Care") # docharity("http://www.thechildsurvivalsite.com","Donate Vitamin A") # docharity("http://www.thelandminesite.com","Save Lives and Limbs") # freedonation.com uses static URLs freedonation[1] = "http://www.freedonation.com/aids/aids_thankyou.php3" freedonation[2] = "http://www.freedonation.com/arts/arts_thankyou.php3" freedonation[3] = "http://www.freedonation.com/cancer/cancer_thankyou.php3" freedonation[4] = "http://www.freedonation.com/children/children_thankyou.php3" freedonation[5] = "http://www.freedonation.com/edu/edu_thankyou.php3" freedonation[6] = "http://www.freedonation.com/envir/envir_thankyou.php3" freedonation[7] = "http://www.freedonation.com/homeless/homeless_thankyou.php3" freedonation[8] = "http://www.freedonation.com/hunger/hunger_thankyou.php3" for (i in freedonation) system(lynxdump" "freedonation[i]" >> "dest) } function docharity(x,y, check, checkcmd, tries, tempfile, whoami) { if (debug) print "Starting charity "x"." check = 0; tries = 0 "whoami" | getline whoami; close("whoami") while ((check == 0) && (tries < 10)) { if (debug) print "check = "check", tries = "tries tempfile = systime()"_"whoami"_charities.tmp" if (debug) print "tempfile = /tmp/"tempfile checkcmd = "ls /tmp/ | grep "tempfile if (debug) { print "looking for file..." system("ls /tmp/ | grep "tempfile) print "that's it." } if ((checkcmd | getline)>0) { if (debug) print "found, trying again in 5." close(checkcmd); system("sleep 5") tries++ } else { if (debug) print "not found, moving to function." check++; docharity2(x,y,tempfile) } } } function docharity2(x,y,tempfile, refnum,regexp1,regexp2,regexp3,address) { # x is the site address, 'http://foo.com' # y is the tag line that goes with the link, e.g. "Donate Free Food" if (debug) print "Moving to function for charity "x"." system(lynxdump" "x" >> "tempfile) if (debug) { print "dumping "x":"; system(lynxdump" "x); print "Site \ "x" dumped."} regexp1 = "\[[0-9]+\]"y ; regexp2 ="[^\\[]*\\[|\\]|"y".*" if (debug) print "looking for "regexp1 while ((getline < tempfile) > 0) { if ($0 ~ regexp1) { gsub(regexp2,"",$0) ; refnum = $0 if (debug) print "\nReference line '"y"' found; refnum ="refnum break } } regexp3 = refnum". http://" close(tempfile) if (refnum) while ((getline < tempfile) > 0) { if ($0 ~ regexp3) { if (debug) { print "\nReference number "refnum" found in line \n"$0"\n" print "Looking for regexp "regexp3 } sub(".*http://","http://",$0) ; address = $0 if (debug) print "regexp found; address is "address break } } close(tempfile) if (address) { if (debug) print "address found, dumping now." gsub("'","",address); system(lynxdump" '"address"' >> "dest) if (debug) print "address dumped." } if (debug) print "removing tempfile "tempfile system("rm -f "tempfile) }