LinuxQuestions.org
Help answer threads with 0 replies.
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 02-08-2013, 03:04 PM   #1
GenericLinuxUser
LQ Newbie
 
Registered: Mar 2012
Posts: 8

Rep: Reputation: Disabled
awk script to get minute changes


I troubleshoot software and review text log files with time stamps and procedure calls. I am often in a position where it would be good (if not essential) to see when a procedure is taking a long time. I created an awk one-liner with egerp (as a learning exercise) that will scan for when a time increments by a minute and then output that line and the previous line from the last minute to a file. I applied this for the /var/log/messages here but naturally you can use this for any file with times (or numbers). For example, here I it went from 04 to 16, 16 to 39 and 39 to 43...

Feb 3 01:04:12 root nmbd[3686]: server01 42849003 (Citrix PS 4.5)
Feb 3 01:16:12 root xinetd[3504]: START: telnet pid=5273 from=127.0.0.1

Feb 3 01:16:14 root xinetd[3504]: EXIT: telnet status=0 pid=2434 duration=1835(sec)
Feb 3 01:39:48 root ntpd[3522]: synchronized to LOCAL(0), stratum 10

Feb 3 01:39:48 root ntpd[3522]: synchronized to LOCAL(0), stratum 10
Feb 3 01:43:26 root xinetd[3504]: START: telnet pid=26276 from=127.0.0.1

I have no questions, I've gotten help here before and thought I'd pay it forward a little. I was unable to find something like this using awk on the Internet (its hard to word the search however) so perhaps someone will find this useful. I'm also sure a supreme awk master could do better, all I know is it works for me. Cheers.

Code:
egrep '[0123456789][0123456789]:[0123456789][0123456789]:[0123456789][0123456789]' messages | awk '{if (FNR == 1){t=substr($0,11,2); u=$0;} else {if (substr($0,11,2) > t){print u "\n" $0 "\n"; t=substr($0,11,2); u=$0;} else {t=substr($0,11,2); u=$0;}}}' > minute-increments
 
Old 02-08-2013, 04:10 PM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Slack14_64_Multilib
Posts: 3,065
Blog Entries: 4

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
That rocks!
 
Old 02-08-2013, 08:41 PM   #3
GenericLinuxUser
LQ Newbie
 
Registered: Mar 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
glad you like it Habitual
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
Need to run a script for any user logged in every minute unassassinable Linux - Desktop 21 02-24-2011 03:39 PM
Need help with script for check for a file that has changed in the last minute EclipseAgent Programming 10 02-12-2009 07:46 PM
running a php script every minute navneet77 Programming 15 11-26-2008 08:55 AM
X-Chat script to enter a command every minute eam Programming 2 08-30-2004 03:25 AM


All times are GMT -5. The time now is 11:24 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration