Why didn't you use latexmk? It deals with the recompiling for you.