The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
who truncates the output? redirection? tty? Bug? fredy UNIX for Advanced & Expert Users 7 12-10-2006 02:21 AM
Asking about shell script input output redirection trivektor Shell Programming and Scripting 1 10-18-2006 01:13 AM
redirection of ladebug output yakari UNIX for Advanced & Expert Users 2 10-06-2006 02:23 AM
Standard output and redirection jerardfjay Shell Programming and Scripting 2 06-27-2005 11:03 AM
Bash multiple output redirection yoi2hot4ya Shell Programming and Scripting 2 05-31-2005 12:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-04-2006
_Spare_Ribs_'s Avatar
_Spare_Ribs_ _Spare_Ribs_ is offline
Registered User
  
 

Join Date: Dec 2006
Location: /dev/null
Posts: 72
Redirection of output (for logging)

Hi,

Currently I'm working on a lenghty script so I figured it would be useful to create a logfile so that output that is displayed on the users screen is also stored in the log file for later reference...... kinda like the whole point of a log file! Anyway, I was just wondering if there was an easier way to modify my existing code without having to duplicate every "echo" command and redirect the duplicated "echo" command to the log.

Example:

Code:
echo "This is my first echo"
echo "This is my first echo" >> /myLogFile.txt

echo "This is my second echo"
echo "This is my second echo" >> /myLogFile.txt
I figure there must be a way to do this without having to duplicate each line but not sure how. Any help would great.

Thanks.

Paulo.
  #2 (permalink)  
Old 12-04-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
look into tee - man tee
  #3 (permalink)  
Old 12-04-2006
_Spare_Ribs_'s Avatar
_Spare_Ribs_ _Spare_Ribs_ is offline
Registered User
  
 

Join Date: Dec 2006
Location: /dev/null
Posts: 72
I looked at tee and this reads from standard input so when I execute the following -

Code:
tee -a test_file
it gives me a prompt to enter input which is then redirected to standard output and a log file called test_file.

I guess I didn't make it too clear, but in the example in my original post the echo commands are all in a long script. Example:

Code:
#!/bin/bash
#
# Test log script
#
declare LOG="AppRemove.log"

touch /$LOG

echo "This is the first line"
echo "This is the first line" >> /$LOG

echo "This is the second line"
echo "This is the second line" >> /$LOG
#
#....... and so on
#
  #4 (permalink)  
Old 12-04-2006
Manish Jha Manish Jha is offline
Registered User
  
 

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
use this:

echo "This is my first echo" | tee -a /myLogFile.txt
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0