commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Open a terminal (urxvt in this case) to connect to a screen session (named "main") and create the screen session if necessary.
Ping machine once, waiting 1 second for response until failing. Upon fail, ssh globally, otherwise ssh locally.