Last active
February 24, 2022 16:01
-
-
Save lgaetz/b06c58aa349bc84348b12fc5d908da11 to your computer and use it in GitHub Desktop.
Bash script to display log lines with unixtime to human readable date
This file contains 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
#! /bin/bash | |
# Display logs files with lines that begin with a 10 digit unixtime to human readable date | |
# save in /usr/sbin/ and make it executable | |
# | |
# Latest version: https://gist.github.com/lgaetz/b06c58aa349bc84348b12fc5d908da11 | |
# | |
# Usage: | |
# cat /etc/asterisk/firewall.log | santiago | |
# santiago /var/log/asterisk/queue_log | |
# | |
# License: GNU/GPL3+ | |
# | |
# History | |
# 2022-02-24 First commit | |
if [[ -a $1 ]]; then | |
cat $1 | awk '{sub(/[0-9]{10}/, strftime("%Y-%m-%d %H:%M:%S", substr($0,0,10)))}1' | |
else | |
awk '{sub(/[0-9]{10}/, strftime("%Y-%m-%d %H:%M:%S", substr($0,0,10)))}1' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment