Skip to content
/ timegrep Public

Utility to grep log between two dates or tail last lines to time ago.

Notifications You must be signed in to change notification settings

abbat/timegrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timegrep

Utility to grep log between two dates or tail last lines to time ago similar dategrep or dateutils.

Examples

Grep last minute from current nginx access log (binary search):

$ timegrep --format=nginx --minutes=1 /var/log/nginx/access.log

Grep datetime interval from archive log (sequential read data from stdin):

$ zcat archive.log.gz | timegrep --start='2017:09:01 15:23:00' --stop='2017:09:01 16:32:00'

Download / Install

$ git clone https://github.com/abbat/timegrep.git
$ make && sudo make install

To compile with own flags use USER_CFLAGS and USER_LDFLAGS variables. For example for i386 static binary with musl libc:

$ CC=musl-gcc32 USER_CFLAGS=-m32 USER_LDFLAGS='-L/usr/lib/i386-linux-gnu -m32 -static -Wl,-melf_i386' make

Usage

timegrep [options] [files]

Options

  • --help, -? - print help message and named datetime formats;
  • --version, -v - print program version and exit;
  • --format, -e - datetime format (default: 'default');
  • --start, -f - datetime to start search (default: now);
  • --stop, -t - datetime to stop search (default: now);
  • --seconds, -s - seconds to substract from --start (default: 0);
  • --minutes, -m - minutes to substract from --start (default: 0);
  • --hours, -h - hours to substract from --start (default: 0).

See strptime(3) for format details. See --help for list of format aliases.

Exit code

  • 0 - successful completion;
  • 1 - nothing found;
  • 2 - general application error.

How to help

  • Translate this document or man page to your native language;
  • Proofreading README.md or man page with your native language;
  • Share, Like, RT to your friends;
  • Send PRs if you are developer.