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
problem with redirect stdout to file mlucas UNIX for Advanced & Expert Users 3 12-06-2006 10:53 AM
PHP Redirect perleo Shell Programming and Scripting 2 05-11-2003 11:17 AM
Redirect Xterm barisgultekin UNIX for Dummies Questions & Answers 1 07-18-2002 01:33 PM
Need to redirect the messages gaur_amar UNIX for Dummies Questions & Answers 2 06-25-2002 11:00 AM
Redirect <Therapy> IP Networking 1 03-20-2002 08:54 AM

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 10-09-2007
2dumb 2dumb is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 40
Redirect Problem

I am using the time command in a script however the output of the time command will display on my screen but not my output file. Any Ideas on how to fix this?

> cat test.sh
#############################
#!/usr/bin/sh

for COMMAND in pwd
do
time ${COMMAND}
done | sed "s/^/ /g" | tee -a test.out
#############################

> test.sh

real 0m0.00s
user 0m0.00s
sys 0m0.00s
/tmp


> cat test.out
/tmp
  #2 (permalink)  
Old 10-09-2007
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
#!/usr/bin/sh

for COMMAND in pwd
do
time ${COMMAND} | sed "s/^/ /g" | tee -a test.out
done


cheers,
Devaraj Takhellambam
  #3 (permalink)  
Old 10-09-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
The time command output its information to stderr, not stdout so you would need to redirect stderr.
Code:
#!/usr/bin/sh

for COMMAND in pwd
do
time ${COMMAND}
done 2>&1 | sed "s/^/ /g" | tee -a test.out
  #4 (permalink)  
Old 10-09-2007
2dumb 2dumb is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 40
devtakh that didn't seem to do any different.

reborg that did work. i thought i tired this early as "done | sed "s/^/ /g" | tee -a test.out 2>&1" but it didnt seem to work for me. thanks for your help.
  #5 (permalink)  
Old 10-09-2007
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
gotcha...
since time command doesn't display on stdout..
2>&1 does the trick..thats great.
so you can play around with 2>&1..redirecting stderr to stdout and then do whatever you may want..


cheers,
Devaraj Takhellambam
Sponsored Links
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 03:04 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