He we will discuss about how to make customization and improvement to the OpenKM source code.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
I think in this case a cron tab will be the better option, because with scripting is more complicate build some kind of logic. Other solution is implementing minimal application with webservices. Make some query, and delete some results.