Keep in mind, this script requires you to be logged in, so unless you completely remove all security checks, you're not going to be able to automate it with cron; it'd probably be easier to hack a copy of the file and weed out all ubb specific variables and then call it from cron (personally I'd make a script with the prune queries and just call that from cron).