回应“写”信息
  想知道是否有人知道一种方法来捕获和识别到终端的传入write命令。  我已经尝试过使用script -f ,然后使用tail -f在while循环中跟踪输出,但由于正在追踪的终端不启动write ,所以不会输出。  不幸的是,我没有root权限,不能和pts或screendump一起玩,想知道是否有人知道一种方法来实现这一点? 
例:
Terminal 1 $ echo hello | write Terminal 2
Terminal 2 $
Message from Terminal 1 on pts/0 at 23:48 ...
hello
EOF
*Cause a trigger from which I can send a return message
我想不出任何明显的方式来做到这一点。 这是为什么...
你的shell收到它的输入,并将它的输出发送给一些终端设备:
   +-----------+
   |           |
   |   bash    |
   |           |
   +-----------+
         ^ |
         | |
         | v
      +----------------------+
      | some terminal device |
      +----------------------+
  write写入终端时,它将数据直接发送到相同的终端设备。  它不会离开你的外壳。 
   +-----------+     +-----------+
   |           |     |           |
   |   bash    |     |   write   |
   |           |     |           |
   +-----------+     +-----------+
         ^ |             |
         | |             |
         | v             v
      +----------------------+
      | some terminal device |
      +----------------------+
  因此,为了能够捕获通过write发送的内容,您需要一些由终端设备本身提供的钩子,我不认为有什么可以用来做到这一点。 
  那么script如何工作,为什么它不捕获write输出? 
  script也不能钩入终端设备。  它真的想在你的shell和你的终端之间进行自我介入,但是没有一个好的方法可以直接做到这一点。 
因此,它创建了一个新的终端设备(一个伪终端,也称为“pty”),并在其中运行一个新的shell。 一个pty包含两个方面:“主”,它只是一个字节流,和一个“奴隶”,它看起来就像任何其他交互式终端设备。
  新的shell连接到从属端, script控制主端 - 这意味着它可以将字节流保存到一个文件,以及在新shell和原始终端之间转发它们: 
   +-----------+
   |           |
   |   bash    |
   |           |
   +-----------+
         ^ |
         | |
         | v
+-----------------+  <=== slave side of pty -- presents the interface of
| pseudo-terminal |                                an interactive terminal
+-----------------+  <=== master side of pty -- just a stream of bytes
         ^ |                      
         | v     
   +-----------+
   |           |
   |  script   |
   |           |
   +-----------+
         ^ |
         | |
         | v
      +----------------------+
      | some terminal device |
      +----------------------+
  现在您可以看到, write原始终端设备可以绕过所有内容,就像上面的简单情况一样: 
   +-----------+
   |           |
   |   bash    |
   |           |
   +-----------+
         ^ |
         | |
         | v
+-----------------+  <=== slave side of pty -- presents the interface of
| pseudo-terminal |                                an interactive terminal
+-----------------+  <=== master side of pty -- just a stream of bytes
         ^ |                      
         | v     
   +-----------+     +-----------+
   |           |     |           |
   |  script   |     |   write   |
   |           |     |           |
   +-----------+     +-----------+
         ^ |             |
         | |             |
         | v             v
      +----------------------+
      | some terminal device |
      +----------------------+
  如果您在此处将数据写入新终端的从属端,您将看到输出显示,因为它将出现在主端的数据流中, script可以看到。  你可以从shell script的tty命令中找到新的pty的名字。 
  不幸的是,这对write没有帮助,因为您可能无法write它:您的登录会话与原始终端相关联,而不是新的终端,并且write可能会抱怨您未登录。但是,如果你例如echo hello >/dev/pts/NNN ,你会发现它显示在script输出中。 
