⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsg11.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 5 页
字号:


<P>to set the ownership of /dev/ttyS0 (or whichever port you are working with) to root.tty, a special Linux ownership for the device driver files that provides the startup daemons with access.







<BR>







<P>You also need to change the entry in the /etc/ttys file to include the terminal type and device you have added so that the startup of the terminal can be performed properly. Because the /etc/inittab file already contains entries for the standard serial ports, you can edit the entry for your new terminal's port, if necessary, to set the baud rate and other parameters that may be required.







<BR>







<BR>







<A NAME="E68E63"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Setting Terminal Behavior with stty and tset</B></FONT></CENTER></H3>







<BR>







<P>The stty command enables you to change and query a terminal option. The stty command is very complex, with dozens of options that modify the behavior of the terminal device driver. Luckily, only the most intense system administrators have to use the many options, so this section ignores most of the details. If you are curious, check the man page for more information.







<BR>







<P>To see the current settings of a terminal, use the stty command without any arguments or with just the device name, such as







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">stty /dev/ttyS1</FONT></PRE>







<P>The stty utility displays a set of parameters that indicate how the terminal is configured. You can use this information to verify that the terminal has read the configuration information properly from the /etc/inittab and /etc/gettydefs files. If the parameters don't match, check the configuration files to see whether there is a typographic error (very common) or an illegal command.







<BR>







<P>Like stty, the tset command has many options, most of which are seldom used (especially if you are not dealing with strange terminals and weird connectors). The tset command is used to initialize the terminal driver with a terminal's command set. If the tset command is given with a specific argument, it uses that. Otherwise, it uses the value defined in the TERM environment variable.







<BR>







<P>You can use tset within the startup files of a user who always logs in from a remote terminal (through a modem) to force a particular configuration, saving a few setup commands. If you put the command







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">tset -m dialup:vt100</FONT></PRE>







<P>in the shell startup file (.profile, .cshrc, and so on), the terminal type will be set to vt100 every time a connection is made through the modem. Of course, this command sets the terminal type even if someone isn't using a VT100 terminal. You can use the command







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">tset -m dialup:?vt100</FONT></PRE>







<P>to have the user connecting through the modem prompted for the terminal type. The prompt will look like the following:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">TERM=(vt100)?</FONT></PRE>







<P>If the user presses Enter, the TERM variable is set to vt100. If the user doesn't want to use that value, the user can enter the correct string at the prompt.







<BR>







<P>In the examples shown so far, tset seems to be quite simple, but it has a very complex structure when dealing with hardwired terminals. To properly configure a terminal connected through a serial port, you need a command like the following:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">eval `tset -s -Q -m dialup:?vt100 -m switch:z29`</FONT></PRE>







<P>The full details of this type of command are unimportant for most system administrators. If you want more information, check the man pages for tset and stty that came with your Linux system.







<BR>







<BR>







<A NAME="E68E64"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Resetting a Screwy Terminal</B></FONT></CENTER></H3>







<BR>







<P>Every now and again a terminal connected through a serial port starts acting screwy, either not showing a prompt or generating garbage. There are two quick ways to try to reset the terminal. If they don't work, you should shut down the terminal and restart it. (You may have to kill the processes that were running on the terminal.)







<BR>







<P>The first approach is to issue a set of Ctrl+J characters on the screwy terminal, and then type stty sane followed by another Ctrl+J. The command stty sane should reset the terminal characteristics to normal (rereading the terminal characteristics from the configuration files). You probably won't see the letters you are typing, so enter them carefully. If you make a mistake, start the process again with a couple of Ctrl+Js. If the terminal isn't behaving at this point, type reset and press Enter or Ctrl+J. If this action doesn't work, you should reset the terminal manually.







<BR>







<P>Often, a problem with a terminal is not with the Linux software but the terminal itself. You can easily cure this type of problem by turning off the terminal, waiting a few seconds, and then turning it back on. If the problem was a terminal character code, the terminal should behave immediately. If it doesn't, check the processes running on the main Linux machine; there may be a hung process or runaway routine. You can kill the processes for that terminal and restart it.







<BR>







<BR>







<A NAME="E68E65"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Using term</B></FONT></CENTER></H3>







<BR>







<P>The term program, which was developed by Michael O'Reilly, is included with many versions of Linux and is readily available on FTP and BBS sites. This program enables you to multiplex your serial lines so that you can support more than one device on a line. You can, for example, use the same serial port to control both a terminal (including an X terminal) and a modem simultaneously. The general process for working with term is to log in to a remote machine normally, run the term program on the remote, and then run term locally. Once the two term processes are properly talking, you can use the same line for your terminal and modem sessions, transferring files while you continue to move around the remote filesystem.







<BR>







<P>Although term shares many of the features of more complex TCP/IP protocols such as PPP and SLIP, it is unique in that it requires no kernel drivers. The term program functions by essentially making your serial port into a service port, much as SLIP and PPP do. The program manages the connection requests coming into the serial port and can maintain multiple processes through that port. The machine on which the serial port is based, called the server, can talk to other machines or peripherals (the clients) through the serial port protocol term imposes.







<BR>







<BR>







<A NAME="E69E103"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Installing term</B></FONT></CENTER></H4>







<BR>







<P>Most Linux distributions include a compiled version of the term utility, so you don't have to compile the program. If you have only source code, you must compile it using the make utility. Each distribution supplies instructions for compiling term. Several versions of term are currently available, and each version has slightly different compilation processes and requirements. Check the documentation carefully before you begin the compilation.







<BR>







<P>The term system requires you to set a number of environment variables. Because any system user can run term, these variables should be defined for each user in the user's startup files. If the root login wants to use term, the environment variables must be defined in the root startup files. The environment variables that are important to term are as follows:







<BR>







<UL>







<LI>The TERMDIR variable defines the directory term uses as its home directory (usually your home directory).







<BR>







<BR>







<LI>The TERMSHARE variable defines the directory to be used when term is in shared mode (usually the same directory as TERMDIR).







<BR>







<BR>







<LI>The TERMMODE variable indicates whether term should run in private or shared mode.







<BR>







<BR>







</UL>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE>For versions of term prior to 1.16, only the TERMDIR environment variable is necessary because these versions do not support private and shared mode.</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<P>The commands needed to set the environment variables differ depending on the shell you use. The TERMDIR variable is usually set to your home directory, so it is defined in the following manner for the C shell or compatible (including tcsh) in the .cshrc or .login file:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">setenv TERMDIR $HOME</FONT></PRE>







<P>In the Bourne and Korn shells (and their compatible shells), this variable is defined in the .profile file using the following lines:







<BR>







<PRE>







<FONT COLOR="#000080">TERMDIR=$HOME







export TERMDIR</FONT></PRE>







<P>You can explicitly define the directories if you want, as in the following example:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">setenv TERMDIR /usr/tparker/termdir</FONT></PRE>







<P>If you are running a version of term later than 1.15, term supports shared and private usage. Define the TERMMODE variable in the same startup location as the TERMDIR command. For the C shell and compatible shells, use the following line if you want to run in private mode:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">setenv TERMMODE 0</FONT></PRE>







<P>For the Bourne and Korn shells (and compatibles), you can set term to run in private mode with the following lines:







<BR>







<PRE>







<FONT COLOR="#000080">TERMMODE=0







export TERMMODE</FONT></PRE>







<P>If you want to run in shared mode, set the TERMMODE variable to a value of 1, and define the TERMSHARE variable to show where the shared directory is, as in the following examples for the C shell:







<BR>







<PRE>







<FONT COLOR="#000080">senenv TERMDIR /usr/tparker/term







setenv TERMMODE 1







setenv TERMSHARE $TERMDIR</FONT></PRE>







<P>The following commands are examples for the Bourne and Korn shells:







<BR>







<PRE>







<FONT COLOR="#000080">TERMDIR=/usr/tparker/term







TERMMODE=1







TERMSHARE=$TERMDIR







export TERMDIR TERMMODE TERMSHARE</FONT></PRE>







<P>Versions of term later than 2.0.0 also have an environment variable called TERMSERVER that must be defined when there is more than one modem and the modems can be used simultaneously. This variable tells term which modem line to use for which connection name. The variable is defined with the name of the connection. Suppose you were setting up three modems and three connections (called conn1, conn2, and conn3) for the C shell. You would add the following line to the startup file to tell term to use Conn1 for its connection:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">setenv TERMSERVER Conn1</FONT></PRE>







<P>For the Bourne and Korn shell, you would use the following commands:







<BR>







<PRE>







<FONT COLOR="#000080">TERMSERVER=Conn1







export TERMSERVER</FONT></PRE>







<P>When the term command is started in these cases, the connection name must be specified as well. For example, with the above configuration information, you would start term with the command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">nohup term -v /dev/modem1 Conn1 &amp;</FONT></PRE>







<P>This command line applies only to those systems with multiple modem connections using term.







<BR>







<BR>







<A NAME="E69E104"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Testing term</B></FONT></CENTER></H4>







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -