Visit Our UNIX and Linux User Community


vmstat output with date & timestamp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers vmstat output with date & timestamp
# 1  
Old 11-14-2006
vmstat output with date & timestamp

Hello all
This is a sample vmstat output ...

$ vmstat 2 2

kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr hx hx hx hx in sy cs us sy id
1 0 0 23105784 7810488 323 767 1742 5 5 0 0 0 0 0 0 683 780 457 43
0 0 0 25216784 8648872 0 2 0 3 3 0 0 0 0 0 0 825 333 671 1 12

I would like to append the date & timestamp, to the end of each line, of the vmstat output, so that the output looks like something like below ...


kthr memory cpu
r b w swap free re .... cs us sy id
1 0 0 23105784 7810488 ....3 457 43 24 33 11/14/2006 15:30:35
0 0 0 25216784 8648872 ....0 671 1 12 87 11/14/2006 15:30:38
0 0 0 25216784 8648880 ....4 755 1 15 84 11/14/2006 15:30:41
0 0 0 25216784 8648888 ....01550 3 15 82 11/14/2006 15:30:44
0 0 0 25216784 8648888 ....0 763 1 11 88 11/14/2006 15:30:47

I tried something like this, but it did not work ...Any ideas ...

$ vmstat 3 5 | date '+%m-%d-%Y %H:%M:%S'

Thanks
# 2  
Old 11-14-2006
You could use a function. You don't say which shell you are using, but this should work for ksh and bash...
Code:
function eg {
  while read line
  do
    printf "$line"
    date '+ %m-%d-%Y %H:%M:%S'
  done
}

..then you can pipe your command through the function, like this...
Code:
vmstat 3 5 | eg

# 3  
Old 11-15-2006
vmstat output with date & timestamp

Awesome ! ...works like a charm ...Thanks a lot Ygor ...
# 4  
Old 11-15-2006
unfortunately ALL the timestamps will be the same as ALL your input into the pipe come in one big chunk.
# 5  
Old 11-15-2006
Quote:
Originally Posted by vgersh99
unfortunately ALL the timestamps will be the same as ALL your input into the pipe come in one big chunk.
ooops, nevermind.
hmmm..... I wonder why does it as what it does. Pipes into functions are NOT buffered?.....

if I do:
Code:
vmstat 3 5 | sed "s/$/$(date)/"

all the timestamps are the same.....
# 6  
Old 11-15-2006
With:
vmstat 3 5 | sed "s/$/$(date)/"
the shell evaluates $(date) before the pipeline starts to run. Only one invocation of date is why the timestamp won't change. Ygor's solution reruns the date command for each line of output.
# 7  
Old 11-15-2006
Quote:
Originally Posted by Perderabo
With:
vmstat 3 5 | sed "s/$/$(date)/"
the shell evaluates $(date) before the pipeline starts to run. Only one invocation of date is why the timestamp won't change. Ygor's solution reruns the date command for each line of output.
ok - good explanation - thanks
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #314
Difficulty: Easy
Pointers were not used in the original C programming language and were added later in in C++.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pls. help with vmstat output...

Hi, Users are reporting performance issue on my Sun Solaris 10 server. I am on the server. I don't see a issue or I might be looking at the wrong thing. Please help. I don't see anything on sar. it's all zero on that. Not sure why users are reporting high CPU and unresponsive at times. ... (1 Reply)
Discussion started by: samnyc
1 Replies

2. Shell Programming and Scripting

grep with date & unique output

alert.log has the entries with ORA-XXXX, .... Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:15:01... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

3. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

4. Solaris

help with vmstat output

Hi all. I need some assistance with my vmstat output. We have several oracle db's running on our solaris machine: SunOS rcworaprd 5.9 Generic_112233-07 sun4u sparc SUNW,Sun-Fire-480R Recently I bumped up our main Oracle database to use 6 GB instead of 4 GB as vmstat output was showing... (1 Reply)
Discussion started by: jamie_collins
1 Replies

5. AIX

vmstat incomprehensible output

Hello everybody, When i run Nmon the output is really incomprehensible vmstat 5 System configuration: lcpu=16 mem=24576MB ent=4.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ -----------------------... (3 Replies)
Discussion started by: Vit0_Corleone
3 Replies

6. Solaris

Howto troubleshoot Perfomance using vmstat & iostat

Can anyone tell me what to look for in terms of abnormal numbers on vmstat or iostat? I have a box with figures pbelow, how would I tell if it's underperforming & what remedies \ perfomance tuning could I perform? thanks all ------------------------------------- -vmstat 5 5 kthr ... (4 Replies)
Discussion started by: stevie_velvet
4 Replies

7. Shell Programming and Scripting

how to display date along with vmstat

Hi Unix Gurus, I have a script which runs vmstat and puts the output to a file. I am pulling the runq,usr,sys,idle columns using awk vmstat 2|awk {'print $1,$14,$15,$16'} Now within this command is there any way i can pass the date too. Please do let me know. Thanks in advance. Arun (5 Replies)
Discussion started by: arunrao_oradba
5 Replies

8. Shell Programming and Scripting

Timestamp & date

Hi, I have list of files as below, with prefix named as date & time. Anyone how to transform each file as below to yyyy-mm-dd hh:mm:ss Regards, (8 Replies)
Discussion started by: rauphelhunter
8 Replies

9. UNIX for Advanced & Expert Users

output of vmstat

i have 2 question about vmstat 1) pin (pagein) output of vmstat is always zero for our system what is the meaning of this? (pout significantly changes depending on the running processes) 2) sometimes react output of vmstat is given in K like 44K sometimes it is given without any unit... (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

10. UNIX for Dummies Questions & Answers

BOX Status with vmstat & top Solaris 2.8

Hi there, Im trying to get the information of vmstat & top in two different logfiles. That not that difficult. vmstat 30 >> myfile.log top >> myfile2.log But I also like to include a timestamp every 30 sec to be sure from what date the logs are. For the Top command I were able to... (2 Replies)
Discussion started by: isacs
2 Replies

Featured Tech Videos