title: Bash: how to duplicate input/output from interactive scripts only in complete lines?
body: <p>How can I capture the input/ output from a script in realtime (such as with tee), but line-by-line instead of character-by-character? My goal is to capture the input typed into the interactive prompts of a script only after backspaces and auto-completion have finished processing (after the RETURN key is hit). </p>
  
  <p>Specifically, I am trying to create a wrapper script for ssh that creates a timestamped log of commands used on remote servers. <a href="http://pastebin.com/VdaKShX8" rel="nofollow noreferrer">The script</a>, which uses tee to redirect the output for filtering, works well, but the redirected output gets jumbled with unsubmitted characters whenever I use the backspace key or the up/down keys to scroll through my remote history. For example: <code>service test stopexitservice test stopart</code> or <code>cd ..logs[1Pls -al</code>.</p>
  
  <p>Perhaps there is a way to capture the terminal's scrollback and redirect that like with tee?</p>
  
  <p>Update: I have found a <a href="https://unix.stackexchange.com/a/139876/37818">character-based cleanup solution</a> that does what I want most of the time. However, I am still hoping for an answer to this question (which may well be msw's answer that it is very difficult to do).  </p>