Another article about terminal session sharing:Linux Terminal session real time sharing(kibitz)

Usescript Command recording, Usescriptreplay 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: commandls index.html lost+found output.session scriptfifo
test test1 timing.log vmware-root [[email protected] tmp]# cd /tmp/test # Do another operation: commandcd
[[email protected] test]# exit # stop recording exit Script done, fileis output.session
among"-t 2> timing.log" Is a required option for playback, No addition"2>" Will cause any input after recording is turned on to be in a garbled state, No addition"-t
timing.log" Will not be availablescriptreplay Playback.timing.log It records how many characters are entered in each time period. adopttiming.log andoutput.session Cooperation can realize playback.

Be careful. Pre recording guaranteetiming.log andoutput.session 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 modifiedtiming.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 fromoutput.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 to0.3-0.7 second, Good results.
[[email protected] ~]# cat timing.log 0.117244 16 0.007955 1 0.298074 1 #
The original2.298074 Change to0.3 second0.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 here2.266129 second, Apparently after a command output, it stops2 Second more0.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 onepipe file, And open the pipeline file at the terminal to be displayed.

At terminal1( As main terminal, I.e. terminal demonstrating operation) Upper usemkfifo 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 # First before permission bitp It representspipe file.

At terminal2 Open uppipe file.
[[email protected] ~]# cat /tmp/scriptfifo

At terminal1 Upper usescript -f Start recording operation, Later operations will be shared on the terminal2 upper.
[[email protected] tmp]# script -f scriptfifo

Useexit You can stop sharing and quit recording.
[[email protected] 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.