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.
Something like this in your .bashrc (assuming bash) should work fairly well:
You would just replace the echo's with whatever it was that you wanted to run.
telnet? I don't recommend its use! One of the following approaches should work for most methods of remote access. (Remote access via a X client, or via VNC or similar being excusable exceptions.)
The Linux console virtual terminals (before you start X) will have tty names like
Checking environment variables can often be subverted by users, if that's a concern.
A more robust general case solution is to walk up the process tree from $$, until you find what you're looking for (or not), use this in a
When run via an
I personally munge the output of "who am i" for other reasons (setting DISPLAY). The last field seems to be the "source" of the login
it should be easy enough to check the format of LOGINHOST to see if it's a "remote" login. telnet is disabled here (as it should be) so I can't explicitly check to see how it's set for telnet