Need help for AWK output with current time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help for AWK output with current time
# 1  
Old 09-26-2008
Bug Need help for AWK output with current time

Hi,

Any suggestion to get the AWK output with time in each line ? I want to have the vmstat in solaris with time append to everyline like this:

kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s1 s3 sd in sy cs us sy id
0 0 0 10409640 2305632 46 78 114 1 1 0 0 1 1 0 0 86 344 411 1 1 98 15:35:00
0 0 0 10400224 2274704 16 20 0 0 0 0 0 0 0 0 0 319 246 356 0 0 100 15:45:00
0 0 0 10400224 2274704 76 281 0 0 0 0 0 0 0 0 0 321 1641 485 1 2 96 15:55:00

The vmstat in AIX has the -t parameter that can do this but not in Solaris.

Thanks for your help in advance.
# 2  
Old 09-26-2008
Code:
vmstat | awk -v time=$( date +%H:%M:%S ) '{print $0, time}'

# 3  
Old 09-26-2008
You can give delay and count as parameters, e.g. this example displays 12 lines with a delay of 5 minutes with the actual time:

Code:
vmstat 300 12|
awk 'NR < 3 {print; next}
{"date +%k:%M:%S" | getline t; close("date +%k:%M:%S")
print $0 " " t}'

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diplay current time stamp in the output

I want to display the command output in a particular format. can you please suggest how can i do this Output of the command Name= XYZ Company= Alpha Department= Accounts Country= Singapore Name=MNC Company= Beta Department= Engineering country=Malta Name=ABC Company=Gamma... (2 Replies)
Discussion started by: swets
2 Replies

2. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

3. Shell Programming and Scripting

To get the time exactly 24hrs from the current time

Hi guys, I am having file which contains below data. 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 ... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

4. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

5. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

6. Shell Programming and Scripting

IF statement dealing with current time

Hi Guys, I am trying to put together a script that will search a txt file for a timestamp and select all text after the initial one up to EOF but the timestamp searched for will depend on the current date So if it the current time is between 0600 and 0700 the script will search a text file... (7 Replies)
Discussion started by: martin0852
7 Replies

7. Shell Programming and Scripting

How far is given date from current time?

give a date and time: Jun 12 21:05:16 06-12-2012 21:05:16 2012/06/12 21:05:16 How can i subtract these dates and times from the current date and time and get back the difference in seconds? a one liner like: echo "Jun 12 21:05:16" | some perl/awk programming 90900s (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Getting current time from wolfram.com using python

Hello to all, I am looking of a python script that can fetch date & time from wolfram or any website that gives correct time. 1. Open woflram.com website 2. Search query "time" 3. Search result displays the time. The script has to contact the website with the search query, take that... (5 Replies)
Discussion started by: frozensmilz
5 Replies

9. Shell Programming and Scripting

Prefix the current date and time to the output of ps

Hi, I need to write a script, that will take the current date, time, and the output from # ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm and spit it to a file, so it'll look like this... PID TID CLS RTPRIO NI PRI PSR %CPU STAT WCHAN COMMAND 1 1 TS... (2 Replies)
Discussion started by: Bloke
2 Replies

10. UNIX for Advanced & Expert Users

Adding # minutes to current time...

Hi all, Looking for a way to add lets say 10 minutes to the current time output should look like 7:15 AM or 7:15 PM. I know that gdate could do this for me but unfortunately its not available on the system I'm working on. So if any one know any way I can accomplish this using the date command it... (7 Replies)
Discussion started by: gptavares
7 Replies
Login or Register to Ask a Question