Last active
August 29, 2015 14:05
-
-
Save binarytemple/5b705e8c7cf5748e4798 to your computer and use it in GitHub Desktop.
insert hostname to logfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### Embed the hostname into all the logfiles from a ZD ticket | |
| This only works with ZSH and relies on glob substitution trick discussed [here](http://serverfault.com/questions/618812/zsh-substitution-cant-do-regex-with-repetition/618822#618822) | |
| ### First, get the list of files. | |
| ``` | |
| errors=(**/*console.log*) | |
| ``` | |
| Then itterate through, embedding the filename into the logfile output. | |
| ``` | |
| for i in $errors | |
| do dbg_hostname=$( echo ${${i}%/*} | cut -d/ -f2 \ | |
| | sed 's/[^\.]*\.[^\.]*.//' ); \ | |
| awk -v dbg_hostname=$dbg_hostname '/error/{print $1 " " $2 " " "[" dbg_hostname "]" " " substr($0, index($0, "[error]"),1000 ) " " }' < $i | |
| done | |
| ``` | |
| ## The result... | |
| 2014-08-04 01:52:59.331 [cloudstoragea03] [error] <0.128.0> Supervisor riak_cs_sup had child riak_cs_gc_d started with riak_cs_gc_d:start_link() at <0.16413.64> exit with reason disconnected in context child_terminated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment