5

I'm trying to build vlc, which is rather complicated and dependent on having the right packages installed, and keeps choking on errors. To trace all my steps, I wish to output what I'm doing to a logfile as I interact with a shell.

As per the helpful answer to this question

I got an elevated prompt by typing the following

(sudo bash) | tee -a vlc_attempt.log

Unfortunately, the output does not include the path prompt, which I wish to see to tell input apart from output.

I tried piping stderr to stdout and vice versa, both of which produce awry results, but enter nothing into the file. Same thing with trying to pipe lxterminal to tee, or starting lxterminal with the --command= option and then the above example command in quotes. Where to go from here?

  • 1
    <jedi-hypno-chars>You want to type man 1 script...</jedi-hypno-chars> – yeti Jul 4 '15 at 15:10
  • 2
    @yeti <jedi-hypno-chars> you want to post an answer, not a comment. You want to post an answer, not a comment. </jedi-hypno-chars> – terdon Jul 4 '15 at 15:16
9

Use script(1) to log everything sent to the terminal:

$ script
Script started, file is typescript
$ # do your work
...
$ # then exit with ^D
$ exit
Script done, file is typescript

You can later look at the output with less:

$ less -r typescript

Beware that the logs will contain all control characters sent to the terminal, such as ANSI colours or whatever else your shell prompt sends. If you don't want control characters in the logs then either simplify your PS1 before running script, or use something like stripansi(1) to clean up the output.

  • Thank you for the answer. While that provides a solution (actually I haven't tested it yet, but I'll assume it does) I would like to know if the method I was originally going for can be made to work and would like to know why I am not seeing the user prompt in the piped output. – Rob F Jul 4 '15 at 15:26
  • 4
    @RobF It can't be made to work. tee is useful for logging output from a command, not interactive sessions. The only reason you get to see a prompt at all is that you aren't redirecting stderr. Once you redirect stderr you won't have a shell prompt at all. Really, use the right tool for the job. – lcd047 Jul 4 '15 at 15:31
  • @RobF no, I don't think it can. The prompt is not part of either stdout or stderr which are the only things you can redirect. This is because in the crushing majority of cases, when you redirect bash's output you don't want the prompt. It would break 99% of pipes. Yours is a very special case. – terdon Jul 4 '15 at 15:31
  • Why would it break the pipes? And is the prompt not a part of any stream, it targets the terminal directly? – Rob F Jul 4 '15 at 16:03
  • @ucd047 it's not that I'm stubbornly wanting to use a knife to eat cereal, I just want to learn something extra while I'm here. – Rob F Jul 4 '15 at 16:05

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.