Check console vs ssh login

If you want to check if the current session is being run via a console vs an SSH shell, this code snippet may be useful.

#!/bin/bash
 
ISLOCAL=$(ps ax | grep $$ | grep -v grep | awk '{ print $2 }')
if [[ $ISLOCAL =~ .*tty.* ]]
then
 echo "Connected to Console"
 
else
 echo "This script can only be run from the console"
 exit 1;
fi