Without worrying about debugging your script, have you considered using pg_standby that's in contrib? It works well and you don't have to fuss with scripts unless you're doing something special.
David
In response to
warm database. at 2008-02-13 05:21:21 from Praveen Kumar (TUV)