All output at console and in a file at same time ?


 
Thread Tools Search this Thread
Operating Systems AIX All output at console and in a file at same time ?
# 1  
Old 06-03-2009
Question All output at console and in a file at same time ?

I have several backup scripts I am improving which involves mksysb, savevg and tar.

Is there a way to have the output of any command sent to the standard output as usual (terminal) and at the same time, send a copy of it all into a file ? Normal outputs and error outputs.

Even if I am checking the status of the backup process, I know my client. They will ask that I display on the terminal the output of the backup so they see it running. But if there is a problem, scrolling the window all the way back to the start of the backup will not be possible (too much output). So if I can send all the output to a file, I could either do a grep from it to spot the error or let the operator view the file to find the errors himself (media error, ...).


added comments...
I saw similar posts done. I am checking them out...


Forgot to mention I am on AIX 4.2 with Korn shell


added comments ...
testing it with TAR

tar cvfpdl /dev/rmt0 . 2>&1 | tee -a /tmp/test.log

it only displays and copies the warnings/errors


tar cvfpdl /dev/rmt0 . | tee -a /tmp/test.log
does the same thing. I need the whole thing on console and in a file.

will continue to check other threads... (by the way, after each backup actions, I am checking the $? status for status and do actions accordingly).

Last edited by Browser_ice; 06-03-2009 at 11:32 PM..
# 2  
Old 06-04-2009
The tee command seems to be working for me but I'm not sending anything to tape and I'm on AIX 5.3 so maybe that's the difference.

Another way to do this would be to send the output to a file and then do a 'tail -f' for the end user to see. Something like:

tar -cvfpdl /dev/rmt0 ./some_dir 1>/tmp/tar.out 2>&1 &
tail -f /tmp/tar.out &

You'll have to do a while loop to watch for when the tar command is completed so you know when to stop the 'tail -f', otherwise it'll never end.

HTH
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies

2. Shell Programming and Scripting

Redirect an output from a script to a file and display it at a console simultaneously

Hi, I'd like to redirect the STDOUT output from my script to a file and simultaneously display it at a console. I've tried this command: myscript.sh | tail -f However, it doesn't end after the script finishes running I've also tried this: myscript.sh | tee ~/results.txt But it writes... (3 Replies)
Discussion started by: wenclu
3 Replies

3. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

4. Shell Programming and Scripting

How to redirect the output of a cvs command to a file as well as the console.

Hi can anyone tell me how to redirect the ouput of a cvs command to a file as well as the console? i tried using cvs add <filename> | tee logFile cvs add <filename> 2>logFile 2>&1 All i could get is only on console or on file. Please help Thanks (2 Replies)
Discussion started by: ankitag2010
2 Replies

5. UNIX for Advanced & Expert Users

Clean console output routed to a file

A friend routed some console output to a file for me. The problem is he used backspace and escape sequences all over the place. Using vi to view the file makes it difficult to read. Is there a program that will process the backspaces and remove the escape sequences? e.g., bash-3.00$ pwd^ (5 Replies)
Discussion started by: eddyq
5 Replies

6. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

7. Shell Programming and Scripting

Redirecting output to both console and to a file

Hi All, Is there a way in Bash we can redirection some output to both console and the file at the same time. ~Parag (2 Replies)
Discussion started by: paragkalra
2 Replies

8. UNIX for Dummies Questions & Answers

routing kill output from console to file

Hi , I am using the following command kill -3 pid ----which will return the thread dump. I want redirect this to file. I tried like the following two ways. kill -3 9843 >> srini.log kill -3 9852 >> srini 2>&1 But those two cases are failed :mad: pls let me knwo is there any... (2 Replies)
Discussion started by: srinivsa
2 Replies

9. UNIX for Advanced & Expert Users

redirect to both file and std output at the same time

hello can some one please help me to redirect the output of a command to both std output and a file. this is little urgent. sridhar (2 Replies)
Discussion started by: send2sridhar
2 Replies

10. UNIX for Dummies Questions & Answers

Output to terminal and file at the same time

Hi all The makefile of a large project produces hundreds of lines of output, which I can't look at any more when the build is finished. If I simply redirect the output to a file, I can't see the progress of the building process... Is there a possibility to redirect the output to a file and at... (1 Reply)
Discussion started by: Charlie
1 Replies
Login or Register to Ask a Question