Skip to content

Pipeable bash script that prints current time while waiting for an input from stdin

Notifications You must be signed in to change notification settings

apankrat/now.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

now.sh

A simple shell script that prints current date/time while waiting for an input and echoing it to the stdout.

It is particularly useful with tail when following log files. Instead of -

tail -F access.log | grep "GET / "

yielding -

173.199.116.xx - - [03/Mar/2013 01:05:18 -0800] "GET / HTTP/1.1" 200 2249 ...
59.167.170.xx - - [03/Mar/2013 01:10:19 -0800] "GET / HTTP/1.1" 200 2307 ...
54.251.76.xx - - [03/Mar/2013 01:16:52 -0800] "GET / HTTP/1.1" 200 2223 ...

use -

tail -F access.log | grep "GET / " | now

and get -

173.199.116.xx - - [03/Mar/2013 01:05:18 -0800] "GET / HTTP/1.1" 200 2249 ...
59.167.170.xx - - [03/Mar/2013 01:10:19 -0800] "GET / HTTP/1.1" 200 2307 ...
54.251.76.xx - - [03/Mar/2013 01:16:52 -0800] "GET / HTTP/1.1" 200 2223 ...
Mar  3 01:20:59 PST 2013

where the last line is reprinted every second with current time.

This gives an idea of when the last log activity was without needing to remember what the server time zone is or what the "-0800" translates to in your local time.

Timestamp format

The timestamp format can be adjusted by passing the date format string to now. For example, this tweak -

tail -F access.log | grep "GET / " | now "[%d/%b/%Y %H:%M:%S %z]"

yields -

173.199.116.xx - - [03/Mar/2013 01:05:18 -0800] "GET / HTTP/1.1" 200 2249 ...
59.167.170.xx - - [03/Mar/2013 01:10:19 -0800] "GET / HTTP/1.1" 200 2307 ...
54.251.76.xx - - [03/Mar/2013 01:16:52 -0800] "GET / HTTP/1.1" 200 2223 ...
[03/Mar/2013 01:20:59 -0800]

About

Pipeable bash script that prints current time while waiting for an input from stdin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages