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. ;)
#!/bin/sh
#
# tty-vs-pts.sh
# 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.
FULL_USER_TTY=`tty`
# strip everything but tty or pts from the string that "tty" produces.
USER_TTY=${FULL_USER_TTY:5:3}
# Check if it is tty or pts.
if [ $USER_TTY == 'tty' ]
then
echo "You are logged in locally using: $FULL_USER_TTY"
else
if [ $USER_TTY == 'pts' ]
then
echo "You are logged in remotely using: $FULL_USER_TTY"
else
# Return failure if it is neither.
echo "Failed to establish type of tty"
fi
fi
Formatted for blogger using: formatmysourcecode.blogspot.com