Add timestamps to recorded session via “script” command

logsterminaltimestampstypescript

In my .bash_profile I have script -a -t 0 session.log which automatically records all terminal input/output into the session.log file. I know this command comes with an optional flag to record the time differences in another file but I was wondering if there was another way to prefix the session.log lines with a timestamp.

Can I pipe the writes to a different shell function before writing it to session.log? Something like this script -a >(add_timestamps.sh >> session.log) (does not work)

Best Answer

There is probably only one thing missing from your example, the option -f to flush the write each time.

script -f >(while read;do date;echo "$REPLY";done >>session.log)
Related Question