So I wrote a small script to help me determine whether or not I was logged in locally or remotely (via ssh). The script is in its bare form here, I use it in my .bash_profile but you might find another use for it.
Important note: This script doesn't really determine if a user is logged in locally or remotely but rather using a tty or pts although the latter usually means that the user is logged in remotely, but not always. ;)
Formatted for blogger using: formatmysourcecode.blogspot.com
# tty vs pts checker by Markus Ulfberg 2009-09-22
# Inteded use is running different scripts wether
# the user logs in remotely or locally.
# Get the name of the tty the user is on.
# strip everything but tty or pts from the string that "tty" produces.
# Check if it is tty or pts.
if [ $USER_TTY == 'tty' ]
echo "You are logged in locally using: $FULL_USER_TTY"
if [ $USER_TTY == 'pts' ]
echo "You are logged in remotely using: $FULL_USER_TTY"
# Return failure if it is neither.
echo "Failed to establish type of tty"