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, 06:55 AM
Post
#2
|
|
![]() 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
#3
|
|
![]() 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
#4
|
|
![]() Group: Members Posts: 692 Joined: 27-January 04 From: Canada Member No.: 1,564 |
|
|
|
|
Apr 10 2007, 11:30 PM
Post
#5
|
|
![]() 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
#6
|
|
|
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... |
|
|
|
daniel3000 Capturing Interactive Shell Script Output Apr 9 2007, 11:47 PM
Da_Blitz i belive there is a pam module, however it might n... Apr 10 2007, 12:31 AM![]() ![]() |
|
Lo-Fi Version | Time is now: 19th June 2013 - 09:11 PM |