LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-13-2006, 08:44 PM   #1
jakev383
QmailToaster Developer
 
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220

Rep: Reputation: 31
Script help for awk and timing commands


I am trying to do a DNS query and find out how long the query took. I'm currently using:

[root@as1 ~]# time dig yahoo.com

Which gives the following results:

; <<>> DiG 9.3.1 <<>> yahoo.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17255
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;yahoo.com. IN A

;; ANSWER SECTION:
yahoo.com. 258 IN A 216.109.112.135
yahoo.com. 258 IN A 66.94.234.13

;; Query time: 2 msec
;; SERVER: 216.55.144.5#53(216.55.144.5)
;; WHEN: Wed Dec 13 21:35:33 2006
;; MSG SIZE rcvd: 59


real 0m0.011s
user 0m0.008s
sys 0m0.004s


But the ONLY part I care about is the real time (0m0.011s). Even then, I'm really only concerned with the integer (0.011), since I'll be using this to compare against another number. You can probably see where I'm going with this. Anyway, I CAN write the data to a test file and grep it out, but am a little fuddled on how to go about it. Does anyone have any suggestions, or a better idea for this? I'm sure awk is what I want for this, but I'm not that awk-savvy.
Any help is greatly appreciated!
 
Old 12-13-2006, 10:20 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
See the TIMEFORMAT variable in the bash manual page to see how to customize the time output. e.g.
Code:
$ TIMEFORMAT="J. R. Bob Dobbs has made %R million dollars today"
$ time sleep 1
J. R. Bob Dobbs has made 1.007 million dollars today
 
Old 12-18-2006, 07:35 PM   #3
jakev383
QmailToaster Developer
 
Registered: Dec 2005
Location: Burlington, NC
Distribution: CentOS, Voyage, Debian, Fedora
Posts: 220

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by matthewg42
See the TIMEFORMAT variable in the bash manual page to see how to customize the time output. e.g.
Code:
$ TIMEFORMAT="J. R. Bob Dobbs has made %R million dollars today"
$ time sleep 1
J. R. Bob Dobbs has made 1.007 million dollars today
Thanks, that gave me the push in the right direction. I now set the TIMEFORMAT variable in the top of my script, and call dig with the +short option to just give me 2 lines of text to deal with.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed and awk in shell script bondoq Linux - Newbie 14 07-27-2007 01:52 AM
how to start timing and print the timing result on portions of java codes ?? alred Programming 2 05-15-2006 10:00 AM
About awk script sachin_keluskar Linux - Software 2 06-24-2005 03:19 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM
How do I run an awk script? davee Programming 2 08-12-2003 08:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:14 PM.

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
Open Source Consulting | Domain Registration