I want to run a command every time I log in to my Ubuntu box, but only if I'm connecting through telnet, not if I'm logging in at the console.

link|improve this question

50% accept rate
feedback

1 Answer

Something like this in your .bashrc (assuming bash) should work fairly well:

if ( tty | egrep -q '\/pts\/' )
then
   echo "is a pts - remote login"
else
   echo "is not a pts - local login"
fi

You would just replace the echo's with whatever it was that you wanted to run.

link|improve this answer
A pty will also be allocated for a X terminal or 'screen' window, so this is not very reliable. – grawity Feb 9 '10 at 18:40
I do open a few terminal windows open when I login at the console... – mos Feb 9 '10 at 19:11
Yeah, this is not going to be good enough. That causes all X terminal windows to print 'is a pts - remote login'. – mos Feb 11 '10 at 16:41
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.