Click to See Complete Forum and Search --> : Bash Script - Detect Remote / Local login


skubiszm
12-11-2003, 03:17 PM
I thought that this would be something everyone does, but I can't find it anywhere. All I need is a simple if-else statement that can tell if I am logged in locally or remotely.

Ex:

if [ local_login ]; then
echo "Do local stuff"
else
echo "Do remote stuff"
fi

I just need to know what to put in the if statement.

-Skubiszm

ph34r
12-11-2003, 03:27 PM
Check the output of "set" - when I ssh into my box, there are entries for SSH_CLIENT and SSH_CONNECTION. Should be simple enough to do

login_type=`set | grep SSH_CONNECTION`

Then use login_type and check to see if it is null or what.

jim mcnamara
12-11-2003, 03:55 PM
try env:

env | grep -q 'SSH_CLIENT'
if [ $? -eq 1 ]; then
# local
else
#remote
fi