Cover V04, I02
Listing 1
Listing 2
Listing 3
Sidebar 1
Sidebar 2


Managing tty Attributes in AIX

Stephen Peterson

I once supported an installation with 200 to 300 tty devices, split between 64- and 128-port concentrators. There were a dozen modems and about a dozen printers of various types. Much of the support was performed via 9600 serial dialup lines. Using the System Management Interface Tool, or SMIT (the ASCII version), to manage tty attributes in this environment turned out to be highly problematic, for these reasons:

1. There are about 50 different tty attributes to scan through, but in my experience only two or three are of interest, so long as you can be sure that all the rest were set to default values.

2. Changing/showing tty attributes in SMIT requires plodding through a list of ttys that can number in the hundreds, then picking one of four screens for a particular attribute. Guess wrong and you must start over. This can become time-consuming over low speed modem-lines.

3. When you are creating ttys, SMIT does not allow you to specify the device name. Instead, it assigns the next available tty number. This is a problem if you prefer to assign tty names consistent with port addresses.

4. It is often handy to be able to add new devices, with attributes identical to existing devices. SMIT does not offer the capability to duplicate ttys, except when you are creating a group of new, identical devices all at once.

Given these limitations, I developed the getattr script (Listing 1). It's a simple command-line tool that saves a lot of time by filtering out all the default settings. This script can be extended in various ways. Two of those ways are shown here: the duptty script (Listing 2), which can create a new tty with attributes matching a specified existing tty, and the alltty script (Listing 3), which can facilitate redefinition of all ttys, printers, and modems on a system after a total reinstall of AIX. This second extension might generate a list of mkdev and duptty commands to be executed after a disaster, or after a CPU upgrade requiring a new level of AIX (such as the model 590, which required AIX 3.2.5).

The getattr Script

The getattr script works with terminals, modems, or printers connected on serial ports. The technique is to use the lsattr command to compare the effective attribute values (generated with the -E flag) with the default values (generated with the -D flag), and report only on the non-default settings. Each lsattr command redirects output into a separate temporary file. The $$ suffix on the filenames is a Korn-shell reserved variable, which is set to the PID of the current process. This serves to provide unique filenames.

The diff command does most of the work. For example, using diff to compare the two lines

term    vt100    TERMINAL type   (our setting, in the t1 file)


term    dumb     TERMINAL type   (the default, in the t2 file)

would produce the following result:

< term  vt100    TERMINAL type
> term  dumb     TERMINAL type

So, to find the lines that differ from the defaults, getattr pipes the diff output to an awk script, which prints out the second and third blank-delimited words of every record for which the first word is a "<". With a little formatting of the print statement, and a BEGIN and END clause added, STDOUT can be redirected to a file and executed as a chdev command. However, I have used it primarily for concise reporting of attributes, to do quick comparisons between devices when trouble-shooting. Since each line in the BEGIN/END construct has an escaped newline to accommodate the multiple-line chdev command, I use the END clause to add a line to the end of the output. A typical invocation, such as

getattr tty0

might produce the following output:

chdev -a term=vt100 \

-a login=enable -l tty0

You can use the script with other device classes as well. The -b option of the diff command causes leading tabs or spaces, as as well as strings between spaces, to be ignored in comparisons. I added this option because column alignment on output from the lsattr command can vary, depending on values for the effective attributes.

The last line deletes the temporary files. The AIX version on our systems has an alias set for rm: the command whence rm outputs the command rm -i. This is handy, since the prompt helps root to avoid accidentally removing the wrong files. In this script, however, it is sensible to specify the full pathname to rm, so this safety feature is deactivated.

There's one other thing to remember. When the $ metacharacter is inside single quotes, the shell does not interpret it. These $ variables have special meaning to the awk interpreter. The awk variables $1, $2, etc., correspond to the first, second, etc. word in the current input line.

The duptty Script

The duptty script (Listing 2) builds on the getattr script. It creates a new tty with attributes identical to any specified existing tty, assigning it whatever devicename and port address you care to specify.

Remembering the -p, -w, -t, -s, and -c parameters is difficult. What I have often done is use SMIT to generate a command to add a device, then note all the parameters in the command that SMIT builds.

Each 64- or 128-port concentrator is assigned a serial adapter number -- such as sa1, sa2, etc. -- when it is configured. You can obtain these numbers from the output of the lsdev -C command. The 64-port concentrators are addressed somewhat differently than the 128-port concentrators. Both boxes have 16 ports numbered 0-15. For the 16-port concentrator, a value such as sa1 corresponds to 1, 2, 3, or 4 concentrators connected to 4 jacks in the adapter installed in a particular microchannel slot, and the connection numbers will be 0-15 on the first, 16-31 on the second, 32-47 on the third, and 48-63 on the fourth. The 128-port concentrators are individually assigned to separate serial adapter numbers, so the connection numbers are much more straightforward, always being 0-15, just as they are labeled on the concentrator.

One caveat concerning 128-port adapters: you cannot include a leading zero on the connection number for ports 0 thru 9. If you do, an invalid connection message will result, and you will probably have some difficulty identifying the problem.

To delete a tty, follow this sequence of steps (substituting the applicable number for NNN):

1. pdisable ttyNNN (this stops the getty process on the tty)

2. chdev -l ttyNNN -a login=disable (again, this halts the getty process)

3. rmdev -dl ttyNNN (this deletes the tty definition)

The alltty script

I have written several throwaway scripts which execute duptty repeatedly, to define ttys after a reconfiguration. For example, if tty0 has a certain set of attributes you want to roll out for ttys on five 128-port concentrators, you could use something like the alltty script (Listing 3). This script will define 80 ttys, on each of five concentrators, giving them device names such as tty100, tty101... tty115, tty200...tty215, etc.

Three-digit tty numbers sort easily. The command:

lsdev -Cc tty | sort -k1

presents the ttys in numerical order only if the ttys are defined with three digits.


This covers most of what I've learned in working with serial devices such as ttys, printers, and modems on an RS/6000. If you have any comments or other feedback, I'd like to hear from you.

About the Author

Steve Peterson is currently employed as an RS/6000 Systems Administrator consultant. His current client is Aetna Life Insurance in Middletown, CT, where he is helping to implement distributed AIX/DB2/DCE applications on multiple RS/6000 systems. Prior to that he worked at The Travelers for 12 years. He can be reached via email at