Are you talking about overall heap size, or about heap usage? Either way, I don't think that such a script will do for you what you think it will. In the former case, heaps tend to increase in size as the app is used, especially with apps such as Java EE application servers. For the latter, once the heap usage reaches a certain amount, a major garbage collection will come along and free a bunch of space. You can observe both of these by hooking up either jconsole or jvisualvm to your Java app.
By the way, what is it that you are really looking for?