UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 2005, 12:08 PM
bluwulf bluwulf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 105 bluwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 33 m 28 sec
Reputation Power: 5
Controlling "output" from UNIX time commmand

I have a problem controlling the output from the UNIX time command, for some strange reason the "output" (specifically the last 3 lines of the output) seems like it can only be directed to the screen, no matter what I do:


Take for example I tried this:

Quote:
bash-2.05# ( time ls -ltr) | tail -3 > timefile_1.txt

real 0m0.008s
user 0m0.000s
sys 0m0.010s




I then looked at the contents of the file timefile_1.txt and I saw this :
Quote:
bash-2.05# more timefile_1.txt
-rw-r--r-- 1 root other 201 Jun 24 10:58 abc123.txt
-rw-r----- 1 sybase sybase 2096629760 Jun 24 11:01 tempdb_dev
-rw-r--r-- 1 root other 0 Jun 24 11:42 timefile_1.txt




**********************************************************

So I experimented some more :

Quote:
bash-2.05# ( time ls -ltr) | tail -3 > timefile_2.txt 2>&1


real 0m0.009s
user 0m0.010s
sys 0m0.000s




As you can see below the last 3 lines of the ls -ltr command has been redirected to the timefile_2.txt file, I need the above 3 lines from the time command

Quote:
bash-2.05# more timefile_2.txt
-rw-r--r-- 1 root other 0 Jun 21 17:13 test123.txt
-rw-r----- 1 sybase other 2096629760 Jun 24 10:01 hello.txt
-rw-r--r-- 1 root other 0 Jun 24 10:58 timefile_2.txt



*********************************************************

My aim is to capture the results (all 3 results) of the time command (I need to do some arithmetic calculations on the values)

I'm working on a SunOS 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Fire-V440 server

Reply With Quote
  #2  
Old June 24th, 2005, 12:33 PM
vgersh99 vgersh99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 47 vgersh99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 41 m 53 sec
Reputation Power: 4
Send a message via AIM to vgersh99 Send a message via MSN to vgersh99 Send a message via Yahoo to vgersh99
why are you doing 'tail -3'?
this works fine for me [ksh on Solaris 7] - capturing both the 'ls' and the 'time' in the same file.
(time ls -l) 1> /tmp/time 2>&1

Reply With Quote
  #3  
Old June 24th, 2005, 03:16 PM
bluwulf bluwulf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 105 bluwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 33 m 28 sec
Reputation Power: 5
Quote:
Originally Posted by vgersh99
why are you doing 'tail -3'?
this works fine for me [ksh on Solaris 7] - capturing both the 'ls' and the 'time' in the same file.
(time ls -l) 1> /tmp/time 2>&1



I don't want to capture the output from the ls -l command only the time. Thanx though for your suggestion.


This is what works :


(time ls -ltr) 2> time.txt 1>/dev/null

Reply With Quote
  #4  
Old June 24th, 2005, 08:00 PM
bluwulf bluwulf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 105 bluwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 33 m 28 sec
Reputation Power: 5
I have another question....would it be possible for me to manipulate the output of the time command without first dumping it to file ? The thing is, I really don't want to create the time.txt file. What I would want to do is isolate the two numeric sections of the output and store them in variables var1 and var2 respectively (note that this would be done inside a loop inside a ksh script):

The following commands isolates the numeric portions of the output that I want :
Quote:
bash-2.05#(time ls -ltr) 2> time.txt 1>/dev/null ; tail -3 time.txt | awk '{print $2}' | awk -Fm '{print $1,$2}' | awk -Fs '{print $1,$2}'


The output of the above command :
Quote:
0 0.008
0 0.000
0 0.010



I would want to initially store 0 in var1 and 0.008 in var2 so I could do some other calculations.

Reply With Quote
  #5  
Old June 24th, 2005, 09:51 PM
bluwulf bluwulf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 105 bluwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 33 m 28 sec
Reputation Power: 5
Ok I think I figured out how to avoid writing the output to a file :


Quote:
(time ls -ltr) 2>&1 1>/dev/null | tail -3 | awk '{print $2}' | awk -Fm '{print $1,$2}' | awk -Fs '{print $1,$2}'




Gives the following output :

Quote:
0 0.009
0 0.000
0 0.010

Reply With Quote
  #6  
Old June 25th, 2005, 10:22 AM
vgersh99 vgersh99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 47 vgersh99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 41 m 53 sec
Reputation Power: 4
Send a message via AIM to vgersh99 Send a message via MSN to vgersh99 Send a message via Yahoo to vgersh99
Code:
(time ls -ltr) 2>&1 1>/dev/null | tail -3 | sed 's/.*\([0-9][0-9]*\)m\(.*\)s$/\1 \2/'

Reply With Quote
  #7  
Old June 27th, 2005, 09:41 AM
bluwulf bluwulf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 105 bluwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 33 m 28 sec
Reputation Power: 5
Quote:
Originally Posted by vgersh99
Code:
(time ls -ltr) 2>&1 1>/dev/null | tail -3 | sed 's/.*\([0-9][0-9]*\)m\(.*\)s$/\1 \2/'




Hey thanx....that code seems better.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Controlling "output" from UNIX time commmand


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway