Writing ( and publishing ) Batch Job
I have rewritten the code found in this thread https://forum.civicrm.org/index.php?topic=19322.0
'Collins22' chicago-orienteering.org/civicrm_code.htm

to suit my specific purposes.  It isn't a civicrm extension nor uses API so far from architecturally pure, but it can be run as a php cron job so does the what is needed.  

I have published the code on github https://github.com/alanef/civicrm-contribs-to-membership maybe it is of use to others - maybe some one wants to contribute and write it properly.