LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-08-2009, 08:20 PM   #1
luusac
LQ Newbie
 
Registered: Aug 2008
Posts: 10

Rep: Reputation: 0
how can I format/parse the output of time?


Hi,
I am using busybox 1.10, where the -f or --format options for 'time' are not supported.

time gives me output like

real 0m 18.72s
user 0m 0.01s
sys 0m 0.06s

How can I parse this to extract the real time in a shell script. I am using sh.

What I am aiming for is something like this:

filedate=`date +"%d-%m-%Y"`
BACKUP_LOG=/backup_$filedate.log
exec >>$BACKUP_LOG 2>&1
timetaken=`time tar -cvz /blah -f /backup_$filedate.tar.gz`
echo "Time Taken: " $timetaken

I only want the real time (not user and sys) and would want to strip out the "real " so that the echo statement would give me something like "Time Taken: 1h 35m 16.23s"

thanks
 
Old 04-08-2009, 10:02 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

As I understand it, you'd like to manipulate and format "date" output ... but you're doing this on BusyBox ... and Busybox doesn't provide "date +FORMAT" options ... or awk ... or much of anything else that would make this job easier.

TWO SUGGESTIONS:
1. Instead of using a script, compile a C program that does everything you need (including call 'popen ("date", "r")' and parse the output for you).

... OR ...

2. Install a more powerful scripting language that has all the built-in features you need (like Perl, for example):

http://www.busybox.net/tinyutils.html

'Hope that helps .. PSM
 
Old 04-08-2009, 10:04 PM   #3
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
Check out the manpage for time, there a lot of built in formatting options.
 
Old 04-08-2009, 10:41 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,073

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by Meson View Post
Check out the manpage for time, there a lot of built in formatting options.
That would be irrelevant, as he said, he's using the busybox version of time. In any case he would need to look at the busybox man page, which he probably did already.

But at least in my version of busybox, sed, awk and grep do exist. I am not a master of busybox, but with these you should be able to do almost anything.
 
Old 04-09-2009, 05:18 AM   #5
luusac
LQ Newbie
 
Registered: Aug 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the responses.
Rather than installing anything else I would like to try and use what I have. My busybox has awk, grep and sed. I would prefer not to write the time output to file and then process it. Can someone give me an example of how I can use awk, grep or sed to achieve what I want (parse output of time)?

Also, can somebody explain why
filedate=`date +"%d-%m-%Y_%H.%M.%S"`
works but
filedate=`date +"%d-%m-%Y_%T"`
does not (it produces wierd file names and the archive doesn't contain the files). date +"%d-%m-%Y_%H:%M:%S" entered at the console works but touch /`date +"%d-%m-%Y_%H:%M:%S"` make a file with the name FXN8FL~6

I have looked at a few pages on filename conventions, but I couldn't find anywhere that says the colon ':' character is not permitted.
thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script to parse following format suomali Programming 11 09-24-2008 01:51 PM
How do I parse the output of a command that output to standard out? gauol Programming 9 01-17-2008 01:54 PM
using sed to parse dir output kcorkran Linux - Newbie 12 01-10-2008 01:17 PM
how to pipe and parse output of a command learnfast Linux - Newbie 2 06-15-2005 04:55 AM
parse output ky-lab_rat Linux - Newbie 7 01-23-2004 01:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration