Use the 'tail' command to monitor everything
blog.robertelder.org
blog.robertelder.org
I think inline pretty-print of JSON/XML/YAML in a log entry.. plus histogram of date/time.. I do these things a lot using various grep/sort/uniq etc pipelines
Wow!
I mention it both because I find it very useful and because, seeing Logfile Navigator, I now see that it desperately needs to have more features :).
https://docs.lnav.org/en/latest/commands.html#adjust-log-tim...
That can be useful for doing minor alignments if clocks are slightly out of sync or doing timezone adjustments.
You can also adjust the time programmatically by updating the "time_offset" column in the "lnav_file" table:
https://docs.lnav.org/en/latest/sqltab.html#lnav-file
Sorry I don't have any examples written up to illustrate this at the moment...
With my old log merging program, you had to supply a regex with groups for the different timezone components and optionally a UTC offset. That worked really well but was a pain to set up. Typically I was using it to look at the same format of files all the time though, so in practice it wasn't that bad.
I'm not really a C/C++ person but maybe I'll try and hack on lnav a bit and see if I can figure out how to add timezone support.
This: https://lnav.org/features#query-logs-using-sql
Reminded me of: logParser https://www.microsoft.com/en-us/download/details.aspx?id=246...
Finally, as the article alludes to, tail can monitor multiple files at once.
Same! If it weren’t for this, I’d use less, as the searchability is often handy.
But it’s funny how just one tiny (and possible unintended?) “feature” turns out to be so dang useful that I keep using tail.
"Dangling by a trivial feature"[0] seems to be a pretty common issue when people recommend 'better' software.
You still can't use it with less, but at least it allows you to mark "segments" of the log without switching to that window and mashing enter.
edit: child comment is a better solution.
bind next-file and prev-file to N and P instead of the default :n and :p.
Makes it much more convenient to flip through files.
[for some reason macos doesn't have the lesskey command even though it has the manual for it. shrug]
alias less='less --follow-name' # still requires <shift>-f to follow
alias tail='tail -F'Use "-S" to toggle the "--chop-long-lines" option at invocation or in interactive mode. This mode shows only one line on the screen for each line in a file and is helpful when viewing a log with entries much longer than the screen width. When lines are chopped less(1) lets you scroll horizontally with <LEFTARROW>/<RIGHTARROW>. Chopped mode also works in tail mode ("F" command or "+F" option).
As others have mentioned the search "/pattern" and filter "&pattern" commands are awesome and they also work in tail mode.
The -J option toggles the status column which is helpful when using search patterns or paging around a file.
Since less(1) has lots of features and navigation methods it’s good to remember the "h" command to show the help page.
I have some scripts that, for example call zcat file.tar.gz | dd of=/dev/mmcblk1 bs=1M status= progress (that last bit it important if your version of dd supports it)
This way I can watch the output of dd in another console if I wanted. I keep finding other uses for it now.
Doesn't this do the same thing as regular gunzip? Or do you prefer the zcat | dd so you can view progress?
cat /var/log/file.log
Output too long, soPress Up, |grep -e useful -e lines
cat /var/log/file.log|grep -e useful -e lines
OK, that looks fine, but I want to tail itPress Up, Home, deldeldel, tail -f (other terminal modes are available)
tail -f /var/log/file.log|grep -e useful -e lines
Exact same command no matter what grep -e you have. You separate the filtering logic from the accessing logic. You can work on one side without worrying about the other. Want to change from cat to bzcat, or tail, or tac, or nc? No problem. Want to add a pre-filter (say strip snmpd errors before you add -n to number your matches in grep), it all stays the same.Now imagine this without "useless" cat
less /var/log/file.log
Press Up, Home, deldeldeldelgrep -e useful -e lines grep -e useful -e lines /var/log/file.log
Then eitherPress up, home, del(n times), tail, end, | grep -e useful -e lines
Or
Press up, up, |grep -e useful -e lines, home, deldeldel, tail -f
Cognative break, extra typing, potentially having to look at what you're typing too rather than muscle memory, all because someone says "cat is useless". My computer isn't from 1965, I don't need to justify every process I run.
</var/log/file.log
</var/log/file.log grep -e useful -e lines
...I used it as a solution to allow me to trigger backups of minecraft worlds from within the game server my son and I share. Anything you put to the 'say' command is written to the game's log. I use
tail -F -n 0 ./logs/latest.log | grep --line-buffer <command-pattern> | sudo xargs -L1 ./some_script.bsh
to detect commands in the log and shuttle them to a custom script. In my case it zips a copy of the world and pushes it to blob storage.
I'm not a unix guy so figuring this all out was quite gratifying.
Spent a while trying to come up with a zero-budget solution for this and during a literal shower thought "Why don't I just tail a log file?" I managed to alter the controllers code to transmit recently written log messages to a minimal server which would just prepend timestamp and origin to the message and append the line to a file. Then each control console would have a Windows-built tail binary that read the file over Samba, wrap it in a batch file that would customize the colors and text a bit, and Plant Tail was born.
The mostly computer-illiterate operators quickly fell in love with it as it provided an amazing degree of transparency to what they were used to and demanded an equivalent utility for all future deployments.
TLDR: Don't rule out simple solutions if you can leverage already existing infrastructure.
(head|tail) -33
to quickly fill the terminal window with text.Edit: that | is an OR not a pipe.
https://docs.lnav.org/en/latest/usage.html#viewing-files
So, you would just run it like so:
$ lnav 'mylog.*' mkdir foo bar
sshfs foo.server:foo.dir/ foo/
sshfs bar.server:bar.dir/ bar/
tail -F foo/foo.log bar/bar.log
A method that doesn't involve sshfs: servers=(foo bar)
pipes=("${servers[@]/%/.pipe}")
mkfifo "${pipes[@]}"
tail -F "${pipes[@]}" &
for p in "${pipes[@]}"; do
true > "$p"
done
for s in "${servers[@]}"; do
ssh "$s" tail -F file.log > "${s/%/.pipe}" &
done
%tail
There's timing issues on this alternative. I just ran each statement separately in a prompt, and luckily it worked. The first `true` statement needs to run after `tail` has started trying to read the first argument, and once that dies, the second run of `true` needs to run after `tail` starts reading the second argument. Last time I did something like this, I just typed the statements without the loops and ran by hand.But you might eventually want to log everything to a third host. Use syslog to send logs across the network and configure your local software to log to syslog.
When you have 10k hosts then sampling 1 in N log lines is still useful as a canary, while avoiding being a firehouse for the central log sampler. If something heinous occurs you can get the unsampled log from the original machine, if you need it.
Much more sophisticated techniques abound, and others will comment I’m sure, but it’s also nice to have the syslog trail as a fallback. You never know in advance what’s going to fail and syslog will show you everything from your Apache logs to kernel bugs and faulty NICs.
That's only for one host. If you mean something akin to:
tail -F <(ssh ...) <(ssh ...)
that wouldn't work, because `tail` would wait for the first `ssh/sed` to close their output (to reach the end of the first pipe) before starting to read the second `ssh/sed`'s output. $ ssh ... >a.log &
$ ssh ... >b.log &
$ tail -F a.log b.loghttps://lnav.org/2021/05/03/tailing-remote-files.html
So, to tail "/path/to/log" on host1 and host2, you'd start lnav with:
$ lnav host1:/path/to/log host2:/path/to/log
[1] - This is the initial release of this feature, so it probably has some performance issues. I'd be interested to know if it worked or not.The documentation for the format files is here:
https://docs.lnav.org/en/latest/formats.html
The "timestamp-format" property in the format definition is an array of the formats to be tried beyond the builtin set.
Here are some example formats written by a user:
https://github.com/aspiers/lnav-formats
I think some of them define their own timestamp format.
So, my advice is always make direct server output stand out in some way (colour, whatever). And, of course think about trapping signals, though this is often not as easy as it might seem.
Same goes for coreutils. I wouldn't mind an "OK" after a cp or mv so I don't have to type echo $? to confirm it didn't crash or something
Don't use CloudWatch? :)
Seems to work ...reasonably enough.
https://manpages.debian.org/experimental/multitail/multitail...
I’d check the logs but my cat is on my keyboard.
I do have cloudfront blocked which breaks many things, not sure yet if it’s related.