Custom Script for Batch Expiry Days

get list of all Batches. for every batch do your changes .

batches = frappe.db.get_list('Batch')
for b in batches : 
     doc = frappe.get_doc('Batch', b["name"])
     doc.expires_in_days = (your code here)
     doc.save()

you can open (bench console) and write the code there to test it . if it works move it to a scheduler event.

some erpnext python documentation :
Document API
Database API