#!/bin/sh # # this is the cp trading post cleanup script # DATE=`date +"%m %d %Y"` export DATE awk ' BEGIN { # get local environment variables today = ENVIRON["DATE"] } /^qty =/ { qty=$0 sub("^qty = ", "", qty) next; } /^email =/ { email=$0 sub("^email =", "", email) next; } /^name =/ { name=$0 sub("^name = ", "", name) next; } /^location =/ { location=$0 sub("^location = ", "", location) next; } /^plants =/ { plants = "plants" available = available "plants " next; } /^seeds =/ { seeds = "seeds" available = available "seeds " next; } /^cuttings =/ { cutting = "cuttings" available = available "cuttings " next; } /^pollen =/ { pollen = "pollen" available = available "pollen " next; } /^female =/ { female= "female" available = available "receptive female plants " next; } /^genus =/ { genus=$0 sub("^genus = ", "", genus) next; } /^species =/ { species=$0 sub("^species = ", "", species) next; } /^expires =/ { expires=$0 sub("^expires = ", "", expires) expire_string = expires if (expires ~ "one week") { expires = 7 } else if (expires ~ "two weeks") { expires = 14 } else if (expires ~ "one month") { expires = 31 } else if (expires ~ "two months") { expires = 62 } else if (expires ~ "four months") { expires = 124 } else if (expires ~ "a year") { expires = 365 } next; } /^description =/ { description=$0 sub("^description = ", "", description) next; } /^date =/ { date=$0 sub("^date = ", "", date) next; } /^antispam =/ { antispam=$0 sub("^antispam = ", "", antispam) next; } /^wanted =/ { wanted=$0 sub("^wanted = ", "", wanted) next; } /^$/ { if (cmpdate(date, today, expires) && antispam == 20957) { print "date =", date if (email != "") print "email =", email if (location != "") print "location =", location if (plants != "") print "plants = P" if (seeds != "") print "seeds = S" if (cuttings != "") print "cuttings = C" if (pollen != "") print "pollen = P" if (female != "") print "female = F" print "genus =", genus if (species != "") { print "species =", species } if (description != "") { print "description =", description } if (qty != "") print "qty =", qty if (wanted != "") print "wanted =", wanted print "expires =", expire_string if (name != "") print "name =", name if (antispam != "") print "antispam =", antispam print "" } qty="" email="" name="" location="" genus="" species="" available="" pollen="" cuttings="" female="" plants="" seeds="" expires="" description="" wanted="" date="" antispam="" next; } /./ { next } END { } function cmpdate(past, today, delta) { # returns 1, or zero depending on if # past + delta >= today # delta is an integer, and today, past # are three integers: Month, day, year # eg: 05 09 60 split(past, a, " ") pm=a[1] pd=a[2] py=a[3] numerical_past = py*365 + pm*31 + pd split(today, b, " ") tm=b[1] td=b[2] ty=b[3] numerical_today = ty*365 + tm*31 + td if ((numerical_past + delta) >= numerical_today) { return 1 } else { return 0 } } ' exit 0