Probably not the sort of answer you are looking for but...
Sounds like this is exactly what make does? Perhaps use a makefile? Make defines a set of targets, the files that it depends on, and rules for creating the targets if one or more of the dependencies becomes newer than the target. It is fairly straightforward to write makefiles, syntax is:
target : dependency
[TAB]command
Plenty of websites decribing it, here's one picked from google's search results:
http://www.wlug.org.nz/MakefileHowto
Obviously this won't help you at all if you don't have make installed, in which case I am sorry!
Hope this helps,
Mark.