1

I like to use tools like history, script, and asciinema to record and review xterm (i.e. bash/sh) sessions for typical, general administration reasons, and also, sometimes for comprehensive study/revision; as a learning tool.

  • I thought of setting the default $SHELL as a direct path to said tools and/or commands, like:

    • /bin/script transcript.log;
    • /bin/asciinema rec -w0.5 term_log.json;
  • But these tools typically rely on having a default $SHELL set (i.e. /bin/bash, /bin/sh, /bin/zsh, etc.).

  • Also, I feel like re-defining system variables (i.e. $SHELL, $TERM, etc.) or trying to get it working with config (*.conf) and dot (~/.bashrc / ~/.bash_profile) files is gona be riddled with all kinds of holes and potential problems.

  • However, every time I decide or realize that I want a transcript of a session, it's after the fact, or I'll be halfway through the interesting part already, or some such scenario.

What's the correct, or best practice to set something like this up to simply log everything (preferably stdin, stdout (and stderr when applicable), etc.) automatically?

  • This doesn't answer your question, but I use GNU screen with a large buffer size and then "hardcopy -h filename" when I realize something interesting has just scrolled by too fast. Also, despite, your hesitance, experiment with putting "script" or something into .login .profile .bash_profile or similar. – barrycarter Sep 25 '16 at 12:34
  • 2
    @barrycarter Maybe if I could get it to save to a new file every time. Maybe I could just use something like "$(date)" for the transcript name.. – tjt263 Sep 25 '16 at 18:20
  • I was thinking something like that too. In my own crontab, I have things like "cp /var/tmp/mesoapi.txt `/bin/date +\%Y\%m\%d.\%H\%M\%S.\%N`". Just be careful with escaping the % signs, they can be tricky. – barrycarter Sep 25 '16 at 22:14
1

Something like this in your .bash_profile or .bashrc might work for you:

if test -t 0 -a -t 1 -a -z "$SCRIPTING"
then
    export SCRIPTING="$HOME/.script.$(date +%Y%m%d_%H%M%S).$$)"
    exec script "$SCRIPTING"
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.