What?!?

Why are you writing a script for this? Its in built. Register an event for database up/down. If your oem setup is correct, and the agent goes down you will recieve a 'Node Unreachable' alert that can be emailed/paged as desired.

Bazza