Another article about terminal session sharing :Linux Terminal session real time sharing (kibitz)
<https://www.cnblogs.com/f-ck-need-u/p/9583753.html>

use script Command recording , use scriptreplay Play recorded actions . Operation of shared terminal , You need to use named pipes to implement .

1.1 Recording
[[email protected] ~]# cd /tmp [[email protected] tmp]# script -t 2> timing.log -a
output.session # start recording Script started, fileis output.session [[email protected] tmp]#
ls # Perform an action : command ls abc.sh ab.sh index.html lost+found output.session scriptfifo
test test1 timing.log vmware-root [[email protected] tmp]# cd /tmp/test # Do another operation : command cd
[[email protected] test]# exit # stop recording exit Script done, fileis output.session
among "-t 2> timing.log" Is a required option for playback , No "2>" Will cause any input after recording is turned on to be in a garbled state , No "-t
timing.log" Will not be available scriptreplay To play back .timing.log It records how many characters are entered in each time period . adopt timing.log and output.session Cooperation can realize playback .

Note that , Pre recording guarantee timing.log and output.session Is an empty file , Otherwise, the operation will be inconsistent during playback .

1.2 playback
[[email protected] test]# scriptreplay timing.log output.session

If you think the playback speed is too slow ( There was a pause in the recording , For example, after entering a command , It took a while to enter another command , This period of time is normal for playback ), Can be modified timing.log file . There are two fields in this file , The first field records the time interval from the last output to this output , The second field is from output.session Number of characters read in . To modify playback speed , Just change the interval of the first field to a little shorter . But it shouldn't be too short , Otherwise, the playback speed is too fast . I think we should change the longer interval to 0.3-0.7 second , Good results .
[[email protected] ~]# cat timing.log 0.117244 16 0.007955 1 0.298074 1 #
The original 2.298074 Change to 0.3 second 0.216628 1 0.092781 1 0.081659 1 0.083258 1 0.419445 1
0.314128 1 0.100810 1 0.083998 30 0.491283 1 0.266129 1 #
It's the same here 2.266129 second , Apparently after a command output, it stops 2 More than seconds 0.099767 1 0.127625 1 0.078809 1 0.181493 1
0.147795 1 0.115808 1 0.077416 1 0.274658 1 0.257042 1 0.524460 4 0.297133 38
0.458018 1 0.416350 1 0.187270 1 0.125467 1 0.100756 8
1.3 Terminal screen sharing

Transmission of information through pipelines . Need a pipe file , And open the pipeline file at the terminal to be displayed .

At the terminal 1( As main terminal , I.e. terminal demonstrating operation ) Use on mkfifo Create pipe file .
[[email protected] tmp]# mkfifo scriptfifo [[email protected] tmp]# ll scriptfifo prw-r--r--
1 root root 0 Sep 26 13:04 scriptfifo # The first one before the permission bit p It represents pipe file .
 

At the terminal 2 Open up pipe file .
[[email protected] ~]# cat /tmp/scriptfifo
 

At the terminal 1 Use on script -f Start recording operation , Later operations will be shared on the terminal 2 upper .
[[email protected] tmp]# script -f scriptfifo
 



use exit You can stop sharing and quit recording .
[[email protected]exi tmp]# exit exit Script done, file is scriptfifo
No operation can be performed after participating in the sharing state on the shared terminal , The actions performed will be recorded , And automatically execute after the master terminal stops sharing .

It should be noted that , Only one session can share a session terminal . If multiple sessions  cat scriptfifo , Will cause the shared cut to appear on multiple different sessions .