Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active February 24, 2022 16:01
Show Gist options
  • Save lgaetz/b06c58aa349bc84348b12fc5d908da11 to your computer and use it in GitHub Desktop.
Save lgaetz/b06c58aa349bc84348b12fc5d908da11 to your computer and use it in GitHub Desktop.
Bash script to display log lines with unixtime to human readable date
#! /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