Check if in SSH

if [ -n "$SSH_TTY" ]; then
    # ...
fi