在linux系统下,有时由于教学或互动的需要,多个不同终端的用户需要看到相同的操作效果。使用vnc可以解决,但占系统资源和网络流量比较多。这里使用多终端同步,可以使位于同一台主机或不同主机的终端显示相同的操作效果,占用资源非常少,十分简单,一个命令即可搞定。
安装必须软件
#yum install tcl expect
(1)确认当前所在终端号:
[root@localhost shell]# w
17:59:31 up 9:47, 5 users, load average: 0.06, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty3 - 08:15 9:44m 0.75s 0.75s ./xrgsu -a
root tty1 :0 17:08 9:47m 9.41s 9.41s /usr/bin/Xorg :
root pts/0 :0.0 17:25 0.00s 3.04s 0.00s w
root pts/1 :0.0 17:33 10:04 0.11s 0.11s bash
root pts/3 :0.0 17:39 46.00s 0.02s 0.02s /bin/bash
(2)以root用户身份向指定终端发起同步命令:
=========pts/0 向pts/1 发起操作========
[root@localhost shell]# kibitz -tty pts/1 root
asking root to type: kibitz -4010
=========pts/1 收到请求 =============
[root@localhost shell]#
Message from root@localhost.localdomain on pts/0 at 18:02 ...
Can we talk? Run: kibitz -4010
EOF
(3)按回车,输入 kibitz -4010
[root@localhost shell]# kibitz -4010
Escape sequence is ^]
此时,pts/0 与pts/1两个终端已同步,控制任何一个终端可以在两边显示操作信息。
(4)再次查看终端状态
[root@localhost shell]# w
18:06:10 up 9:54, 5 users, load average: 0.04, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty3 - 08:15 9:50m 0.76s 0.76s ./xrgsu -a
root tty1 :0 17:08 9:54m 12.66s 12.66s /usr/bin/Xorg :
root pts/0 :0.0 17:25 1:58 5.41s 0.00s expect -- /usr/
root pts/1 :0.0 17:33 0.00s 0.11s 0.00s expect -- /usr/
root pts/3 :0.0 17:39 4:17 0.03s 0.03s /bin/bash
pts/0和pts/1已经通过expect程序同步,pts/3没有同步。
(5)让3个以上终端同步
在pts/0或pts/1终端里向pts/3发起同步请求
[root@localhost shell]# kibitz -tty pts/3 root
asking root to type: kibitz -4046
pts/3收到请求
[root@localhost ~]#
Message from root@localhost.localdomain on pts/2 at 18:10 ...
Can we talk? Run: kibitz -4046
EOF
(6)pts/3按回车,输入 kibitz -4046
[root@localhost ~]# kibitz -4046
Escape sequence is ^]
(7)再次查看终端状态,3个终端都已经同步
[root@localhost shell]# w
18:11:15 up 9:59, 5 users, load average: 0.01, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty3 - 08:15 9:55m 0.77s 0.77s ./xrgsu -a
root tty1 :0 17:08 9:59m 14.51s 14.51s /usr/bin/Xorg :
root pts/0 :0.0 17:25 7:03 7.09s 0.01s expect -- /usr/
root pts/1 :0.0 17:33 1:08 0.11s 0.00s expect -- /usr/
root pts/3 :0.0 17:39 0.00s 0.03s 0.00s expect -- /usr/
相同的原理,即使使用远程登录,不同的终端位于不同的主机上,一样可以使用这样的方法达到终端同步。
=============
man kibitz
kibitz - allow two people to interact with one shell
允许两个用户影响一个shell,即多终端同步