Hello!
With over 10 years of web hosting experience and linux server management I can create a script which make desired actions. Please check my profile for more information: https://www.freelancer.com/u/szabodavidhu.html
I can work for you on hourly basis, my offer is 29USD/hour. I estimate it will take about 4 hours to finish this project.
Do you have direct SSH access to your server?
Do you have preferred script language?
I'm looking forward to work on your project!
Best regards,
David