Home » Questions » Computers [ Ask a new question ]

How to configure a command to run on login, but only if through telnet

How to configure a command to run on login, but only if through telnet

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.

Asked by: Guest | Views: 281
Total answers/comments: 1
bert [Entry]

"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

typeset -a LOGINARRAY
# who am I format: USER TTY MON DAY TIME LOGINHOST,
# use array to get last entry
LOGINARRAY=( $(/usr/bin/who -sum) )
LASTINDEX=$(( ${#LOGINARRAY
  • } - 1))
    LOGINHOST=${LOGINARRAY[$LASTINDEX]}
    LOGINHOST=${LOGINHOST##*\(}
    LOGINHOST=${LOGINHOST%%)*}
    DISPLAY=$LOGINHOST:0
    export DISPLAY

    unset LOGINARRAY LASTINDEX

    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"