Unix Power ToolsUnix Power ToolsSearch this book

3.15. Terminal Setup: Searching Terminal Table

Your system may have an /etc/ttytab or /etc/ttys file that lists the type of each terminal port (tty (Section 24.6)).[9] Here are lines from /etc/ttys on a NetBSD system I use:

[9]Then again, it may not. The RedHat Linux system I tested this on did not; the MacOS X 10.1.5 box I tested it on did.

console "/usr/libexec/getty std.9600"    vt100      on  local
tty00   "/usr/libexec/getty std.9600"    dialup     off local
tty01   "/usr/libexec/getty std.9600"    plugboard  off local
   ...
ttyp0   none                             network    off
   ...

For example, port ttyp0 is network, the type used by xterm (Section 24.20), telnet (Section 1.21), etc.

To change your account configuration based on the tty port type, match the first column of that file to the output of the tty (Section 2.7) command, which shows your current tty pathname. The output of tty starts with /dev or /dev/pts. So, to match your current tty to the file, you need to strip the name to its tail. For example, in bash and ksh, these three lines would put the terminal port type (vt100, plugboard, etc.) into the ttykind shell variable:

tty=`tty`
ttytail=${tty#/dev/}

awk Section 20.10

ttykind=`awk '$1 == "'$ttytail'" {print $3}' /etc/ttys`

Then you can test the value with case (Section 35.10) or if (Section 35.13). In C shells, you can set ttytail by using the :t string modifier (Section 28.5) and test its value with switch or if.

--JP and SJC



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.