Edmond Rodriguez on 4 Sep 2011 08:07:06 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Capturing command line, and stdio and error with bash |
Maybe that would work, as on my machine this seems to put out lots of ^H when scrolling commands. ^C 'ing out of a command not yet entered, may still show the text though. ^[]0;edmondrod@localhost:~^G^[[?1034h[edmondrod@localhost ~]$ echo one^M one^M ^[]0;edmondrod@localhost:~^G[edmondrod@localhost ~]$ wecho^H^[[K^H^[[K^H^[[K^H^[[K^H^[[Kecho two^M two^M ^[]0;edmondrod@localhost:~^G[edmondrod@localhost ~]$ echo three^M three^M ^[]0;edmondrod@localhost:~^G[edmondrod@localhost ~]$ echo four^C^M ^[]0;edmondrod@localhost:~^G[edmondrod@localhost ~]$ ^Gk^H^[[Kset -o vi^M ^[]0;edmondrod@localhost:~^G[edmondrod@localhost ~]$ set -o vi^H^H^H^H^H^H^H^H^Hecho three^H^H^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[C^[[C^[[2Pwo^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[Cone^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[Ctwo^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[Cone^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[Ctwo^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[C^[[Chree^H^H^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[C^[[C^[[2Pwo^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[Cone^H^H^H^H^H^H^H^H^[[C^[[4Pxit^H^H^H^H^[[Ccho one^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[Ctwo^H^H^H^H^H^H^H^H^[[C^[[C^[[C^[[C^[[C^[[Chree^H^H^H^H^H^H^H^H^H^H^[[1Pset -o vi^H^H^H^H^H^H^H^H^H^[[K^G^C^M ^[]0;edmondrod@localhost:~^G[edmondrod@localhost ~]$ set -o vi^H^H^H^H^H^H^H^H^Hecho three^H^H^H^H^[[2Pwo^H^H^Hone^H^H^H^H^H^H^H^[[4Pxit^H^H^H^Hset -o vi^H^H^H^H^H^H^H^H^H^[[5Pexit^H^H^Hcho one^H^H^Htwo^H^Hhree^H^H^H^H^H^H^H^H^H^H^[[1Pset -o vi^H^H^H^H^H^H^H^H^H^[[K^Gexit^M exit^M On Sun, Sep 4, 2011 at 10:50 AM, Edmond Rodriguez <erodrig97.list@gmail.com> wrote: > Yes, I thought of doing something similar, but it still does not cover > things like viewing history. For example pulling up old commands. > You end up with all the commands in the typescript (using script), > though you really only entered one of them (which history records just > fine). Also things like running vi or whatever, I would just want the > "vi xxx" to record, not everything going on in the vi session. > > Imagine that you are doing an install or some meticulous work > manipulating things, and you want to record what you are doing. What > commands you actually entered, and what the applications or shell > outputted, and that is it. Of course, I realize there may be > something out there that does this, but I am trying stay in the > mindset of a modern common Unix or Linux install (writing a script > would be fine), without requesting new software installed. > > History does great recording commands. > > Script of I/O redirection using tee (though pain to type every time), > does great for recording output. > > How to do both in one place? > > > On Sun, Sep 4, 2011 at 10:10 AM, Alan D. Salewski <salewski@att.net> wrote: >> On Sun, Sep 04, 2011 at 08:35:57AM -0400, Edmond Rodriguez spake thus: >>> Well there has been lots of mail about redirection in bash. >> *snip* >> >>> So I would want a script that has only the final result of my command >>> entered (like history does) I entered, not the editing keystrokes as >>> well (back space, emacs or vi control keys....cursor movements), and >>> of course whatever else gets output to the terminal. I realize if a >>> formatting strings goes to the terminal from an *application* I am >>> running, I will get that, but I am just thinking of general basic >>> text i/o going to the terminal from an application. >>> >>> Edmond >> >> Here you go: >> >> I started with the perl program found here: >> >> http://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output/18979#18979 >> >> The text of that is in the 'strip-em' program below. By itself, that >> script could be used to post-process a file created by 'script' (or >> similar). It tries to "remove carriage returns and do backspace-erasing >> of previous characters", and in my simple test it seemed to do all >> right. >> >> But since that's not quite what you're looking for, and because we're >> all on a "redirection in bash" kick, I present the following >> 'script-filt' program. It sets up a named pipe, and then fires up a >> 'strip-em' process in the background to process whatever gets written to >> the pipe. It then launches 'script' and tells it to write to the named >> pipe rather than the normal 'typescript' file. From there it looks like >> a normal 'script' session -- only the logged output is subject to >> filtering. In the end, you're left with a 'typescript-filt' file. The >> filtering is not quite perfect, but it's a good start. >> >> HTH, >> -Al >> >> >> ----script-filt------------------------8<--------------------------------- >> #!/bin/bash >> >> set -e >> >> declare -r pname="filt-${RANDOM}" >> >> mknod "${pname}" p >> >> ./strip-em < "${pname}" > 'typescript-filt' & >> >> script -f "${pname}" >> >> rm -f "${pname}" >> ---------------------------------------8<--------------------------------- >> >> >> >> >> ----strip-em---------------------------8<--------------------------------- >> #!/usr/bin/perl >> while (<>) { >> s/ \e[ #%()*+\-.\/]. | >> \r | # Remove extra carriage returns also >> (?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd >> (?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL) >> (?:\e[P^_]|[\x90\x9e\x9f]) .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST >> \e.|[\x80-\x9f] //xg; >> 1 while s/[^\b][\b]//g; # remove all non-backspace followed by backspace >> print; >> } >> ---------------------------------------8<--------------------------------- >> >> >> >> >> >> -- >> ----------------------------------------------------------------- >> a l a n d. s a l e w s k i salewski@att.net >> 1024D/FA2C3588 EDFA 195F EDF1 0933 1002 6396 7C92 5CB3 FA2C 3588 >> ----------------------------------------------------------------- >> ___________________________________________________________________________ >> Philadelphia Linux Users Group -- http://www.phillylinux.org >> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce >> General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug >> > ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug