Hi
I have heard of a script like doing things similar to that of what you are asking.
I think it is quite possible to do just that with the help of EEM and TCL scripts.
There is a community that handles EEM/TCL specifically.
https://supportforums.cisco.com/community/netpro/private/pilot/eem
and there are several good scripts there already maybe you can modify one of them to suit your needs.
Good luck
HTH