Event logging to file and display to console | tee command is not able to log all info.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Event logging to file and display to console | tee command is not able to log all info.
# 1  
Old 02-24-2012
Question Event logging to file and display to console | tee command is not able to log all info.

My intention is to log the output to a file as well as it should be displayed on the console > I have used tee ( tee -a ${filename} ) command for this purpose. This is working as expected for first few outputs, after some event loggin nothing is gettting logged in to the file but It is displaying on the console.

I can elaborate this.
Code:
echo -ne "$(date +%c) $*" >> ${filename};echo -e "Thank you for selecting Rose Model Extraction !!!\n" | tee -a ${filename}
echo -ne "$(date +%c) $*" >> ${filename};echo -e "Start of taking backups !!!\n" | tee -a ${filename}
........................
........................
echo -ne "$(date +%c) $*" >> ${filename};echo -e "Start of copying Model files !!!\n"  | tee -a ${filename}


Dashed line indicate the operation performing (code). Here in this example first two statements are displaying and logging into log file. But from third statement onwards nothing is getting logged in to the file, but is is displaying on the console. Is this because the command execution speed is more, execution is very quick.?

Thanks,
Sanoop

Last edited by Franklin52; 02-24-2012 at 03:46 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-24-2012
It sunds more like a quoting imbalance, where the te got hidden.
Code:
"  | tee -a ${filename} . . ."

I usually go for the quieter:
Code:
(
everything, but simpler -- no redirection, pipes, multiple tee's
) 2>&1 | tee ${filename-with-date-to-second}

The there is the ever favorite no tee, just log to file, and to watch:
Code:
tail -n +0 -f ${filename}

Sometimes long commands, even sub-shells and scripts, will buffer, stopping mid-line, but usually at each command end the log catches up.

Programmers can help by either calling flush() periodically to clean FILE* buffers, or initially calling setvbuf() to configure line buffering. I used to use setvbuf for a huge buffer, and flush to write whole log blocks in one piece, because I had many servers writing the same logs.
# 3  
Old 02-24-2012
I think that we need to see lines 3+ .
My blind guess for the hidden code is that it starts another Shell.


Ps. It always helps to post what Operaing System and version you have and what Shell you are using.
The "echo -e" says some sort of Sunos to me, but there is very liitle actual Shell in the post.
# 4  
Old 02-27-2012
For instance, if some line does something this, stdin and stdout are changed, no longer default to the display:
Code:
exec > /tmp/stdout.$$ 2> /tmp/stderr.$$

(A bad practice, in my view, as it confuses readers of subsequent lines. If you want to redirect for a while, put that bit in () or {} and redirect just that bit, temporarily.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Syslog not logging successful logging while unlocking server's console

When unlocking a Linux server's console there's no event indicating successful logging Is there a way I can fix this ? I have the following in my rsyslog.conf auth.info /var/log/secure authpriv.info /var/log/secure (1 Reply)
Discussion started by: walterthered
1 Replies

2. Shell Programming and Scripting

Logging success event into file

Hi, I've the following code to log the errors any after the command is executed. # Ksh 88 Version log_path=/home/etc/fls/fls_log.log del_path=/home/etc/fls/to_day rm $del_path/* >> $log_path 2>&1 But I even want to log if the rm command is success without any error along with... (1 Reply)
Discussion started by: smile689
1 Replies

3. 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

4. UNIX for Dummies Questions & Answers

How to write code for a Logging Event?

How do I know what parts of the application to monitor and what means do I use to get this data? Can I use proc? What interactions are important and how do I view them?I would be more descriptive but I have not a clue. Thanks in... (18 Replies)
Discussion started by: theKbStockpiler
18 Replies

5. UNIX for Advanced & Expert Users

Unable to display directory info with ps command

Hello, I start an adapter using the following command - nohup ./start_embargoAdapter >/dev/null 2>&1 & and when I do the following, I can see: /export/home/xxxxx> ps -ef | grep embargo xxxxx 28086 20761 0 23:23:29 pts/7 0:00 grep embargo xxxxx 8866 1 0 Oct 06 ? 0:00... (2 Replies)
Discussion started by: samjna
2 Replies

6. Shell Programming and Scripting

problem with suppressed output to file using echo and tee command

Hi, When I run the following command in terminal it works. The string TEST is appended to a file silently. echo TEST | tee -a file.txt &>/dev/null However, when I paste this same line to a file, say shell1.sh, and use bourne shell . I run this file in terminal, ./shell1.sh. However I... (1 Reply)
Discussion started by: shahanali
1 Replies

7. Shell Programming and Scripting

Is there a way to tee stderr from a command that's redirecting error to a file?

I'm not a complete novice at unix but I'm not all that advanced either. I'm hoping that someone with a little more knowledge than myself has the answer I'm looking for. I'm writing a wrapper script that will be passed user commands from the cron... Ex: ./mywrapper.sh "/usr/bin/ps -ef |... (1 Reply)
Discussion started by: sumgi
1 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. BSD

Logging to /dev/console

Hi, The output of the cat ttys on a free BSD m/c console none unknown off secure # # Serial terminals # The 'dialup' keyword identifies dialin lines to login, fingerd etc. ttyd0 "/usr/libexec/getty std.9600" unknown on secure ttyd1 "/usr/libexec/getty std.9600" dialup off ttyd2... (0 Replies)
Discussion started by: mlalitha
0 Replies

10. UNIX for Dummies Questions & Answers

Logging all console activity to a file - how?

Hi all, Well I've had a bit more experience with Unix-like environments since my last post, now that I have started working on my website in earnest and am doing much of the file manipulation via the command line through SSH. The thing is, I want to be able to log all console activity,... (4 Replies)
Discussion started by: patwa
4 Replies
Login or Register to Ask a Question