![]() ![]() |
Apr 9 2007, 11:47 PM
Post
#1
|
|
![]() Group: Members Posts: 1,002 Joined: 28-April 05 From: Germany Member No.: 7,027 |
Hi guys,
does anyone know how to capture the output (stdout AND stderr) of an interactive shell script to a file? Of course I could write a "| tee ..." behind every single command, but I'd like to avoid that hassle. Using "| tee" on the entire script eats the interactivity ("read -p" output isn't shown on the screen anymore). Thank you! daniel |
|
|
|
Apr 10 2007, 12:31 AM
Post
#2
|
|
![]() Group: Members Posts: 1,565 Joined: 7-April 05 From: Sydney, Australia Member No.: 6,806 |
i belive there is a pam module, however it might not do what you want
i know there is a program out there but its not perfect, you could hack up some messy code using tee as you said by using pipes and file descripter redirection however perhaps bash has an option to allow you to dump IO well lets see what dirty code i can come up with CODE #!/bin/sh # use these for real time logging and processing (ie external program to add timestamps) #mkfifo stdin #mkfifo stdout tee stdin | $* 2>&1 | tee stdout just watch out for stuff that uses the ncurses libary, this will not work with them. same goes for anything using escape chars, or if it does use it make sure you only playback the script on the same term (otherwise escape chars might be diffrent) |
|
|
|
Apr 10 2007, 06:55 AM
Post
#3
|
|
![]() Group: Members Posts: 692 Joined: 27-January 04 From: Canada Member No.: 1,564 |
The script utility saves all command line output. If it's not available for your ROM, it's part of the util-linux kernel package if you want to compile it. HTH
|
|
|
|
Apr 10 2007, 08:59 AM
Post
#4
|
|
![]() Group: Members Posts: 1,002 Joined: 28-April 05 From: Germany Member No.: 7,027 |
QUOTE(grog @ Apr 10 2007, 04:55 PM) The script utility saves all command line output. If it's not available for your ROM, it's part of the util-linux kernel package if you want to compile it. HTH hmm- the util-linux package on http://www.tyrannozaurus.com/feed/beta3/feed/ does not contain "script". Now trying to compile the sources 2.12r. Thanks for the hint! It just looks like what I need! daniel |
|
|
|
Apr 10 2007, 12:01 PM
Post
#5
|
|
![]() Group: Members Posts: 692 Joined: 27-January 04 From: Canada Member No.: 1,564 |
|
|
|
|
Apr 10 2007, 11:30 PM
Post
#6
|
|
![]() Group: Members Posts: 1,002 Joined: 28-April 05 From: Germany Member No.: 7,027 |
QUOTE(grog @ Apr 10 2007, 10:01 PM) QUOTE(daniel3000 @ Apr 10 2007, 10:59 AM) Glad I could help. Don't forget to share Of course I won't! So here is the solution: Attached is the script utility (stripped binary only, compiled for pdaXrom 1.1.0beta3), just unzip and copy it to /usr/bin). I have also developed a nice trick to make usage of "script" totally transparent to the user, so the user still only has to call the shell script as usual. Normally, in order to create a log from a shell script execution, you need to call the script with "script" this way: CODE script -c "shellscript.sh" logfilename This can be automated within the actual shell script to be executed and logged. Just put these lines at the beginning of the shell script: CODE TODAY=`date +%Y-%m-%d_%Hh%M` if [ ! "$1" = "run" ]; then script -c "$0 run" ${TODAY}_LOGFILE echo Created logfile ${TODAY}_LOGFILE exit 0 fi So when calling the shell script as usual, it actually calls "script" which, with the -c parameter, calls the shell script recursively once more to execute its actual contents. The "run" parameter is used to determine if the user calls the script (go into the "if") or if script has called it (run the actual script contents). In the above example, "script" will create a logfile in the currect directory with the name (for example) 2007-04-11_09:25_LOGFILE Interactivity of the shell script, here using mainly echo and read, is fully preserved. Thank you for your help! daniel
Attached File(s)
|
|
|
|
Apr 11 2007, 12:53 AM
Post
#7
|
|
|
Group: Members Posts: 902 Joined: 22-May 04 Member No.: 3,385 |
My preferred solution to this problem is to use Emacs.
When you run the shell in Emacs, either bash or eshell, you can then simply save the buffer to a file, you can browse the shell window like a text file etc. It's superb... |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd May 2013 - 05:21 PM |