Home Linux Blog Memories Me About ?

Dear My
Linux

How to record and replay a terminal session

POST_AT

Paste the following code in $HOME/.profile or $HOME/.bashrc

, I was inspired for internet forums, however I added the exit function a, it's important mainly for SSH. Also included the time parameter, using the time parameter allows us to replay the script record using the scriptreplay --time=FILE1 FILE2 command.

In the case that you want it to be more hidden or system-wide you can add the code into /etc/profile.


mkdir -p $HOME/.log
test "$(ps -ocommand= -p $PPID) | awk '{print $1}')" == 'script'  || script --timing=$HOME/.logs/$(date +%s).time $HOME/.logs/$(date +%s) -q

if [[ "$(ps -ocommand= -p $PPID) | awk '{print $1}')" == 'script' ]]; then
	exit
else
kill -9 $$
fi