I'm sure it can be done in python, but there are perl, expect, etc. scripts already out there. Also, there is a scheduling feature in WCS that can do exactly this. It is in 6.0.132.0 WCS and may be in a 5.x release as well too. (I skipped the 5.x release entirely)