Script for a Force Merge on indexes in ES

I need to run force merge on indexes which are older (no longer being written to or not in active state) for more than "48hours for daily/quaterly indexes" and "33 days for monthly indexes".

This should be run by a script as we have lot many indexes in our environment, could anyone please help on this

Have you looked into Index Lifecycle Management, which has support for forcemerging?