Skip to content

Instantly share code, notes, and snippets.

@leopku
Forked from mikepenz/multitail.md
Last active August 29, 2015 14:11
Show Gist options
  • Save leopku/9cfe5fff41bb017affa4 to your computer and use it in GitHub Desktop.
Save leopku/9cfe5fff41bb017affa4 to your computer and use it in GitHub Desktop.
# Run following command:
curl https://gist.githubusercontent.com/mikepenz/a8a4a52f67a391895a4c/raw/22db5a0c3b009442a9ff8fd454e08f429d706c8c/multitail.sh | sh; source ~/.bashrc
# This will start the script multitail.sh and call source ~/.bashrc afterwards
#try to run
#logt (log-tomcat) output normal /usr/local/tomcat/logs/catalina.out or /var/www/tomcat/logs/catalina.out
logt
#logt (log-tomcat) output overwrite tomcat or logfile /usr/local/$1/logs/$2 or /var/www/$1/logs/$2
logt $1 $2
#log (normal log) and output logfile $1 (... $9)
log $1 (... $9)
#or output predefined logs
log tom, log tomdev, log tomtest
#How-To-MultiTail
q - will quit all windows etc.
b - use to see the buffer (default up to 1000 lines back in history :D)
shift + / - to search (in the 1000 lines)
h - minimal help :D
#manpage
http://linux.die.net/man/1/multitail
#!/bin/sh
echo "############################################################"
echo "############################################################"
echo "apt-get update"
echo "############################################################"
echo "############################################################"
apt-get update # To get the latest package lists
echo "############################################################"
echo "############################################################"
echo "install multitail"
echo "############################################################"
echo "############################################################"
apt-get install multitail -y
echo "############################################################"
echo "############################################################"
echo "############################################################"
echo "############################################################"
echo "create multitail configuration"
multitailconfig='#Possible colors: red, green, yellow, blue, magenta, cyan and white.
# Pick default screen
defaultcscheme:log
# Default colorscheme for tomcat logs
colorscheme:log
cs_re:green:.*INFO.*
cs_re:yellow:.*WARN.*
cs_re:magenta:.*SEVERE.*
cs_re:red:.*FATAL.*
cs_re:red:.*ERROR.*
cs_re:blue:.*DEBUG.*
# /var/log/messages & .../syslog
colorscheme:syslog
cs_re:red:.*kernel.*
cs_re:magenta:.*sshd.*
cs_re:red:.*iptables.*
cs_re:red:.*sensorsd.*
cs_re:yellow:.*nagios.*
cs_re:yellow:.*null.*
cs_re:yellow:.*login.*
cs_re:yellow:.*bsd.*
cs_re:green:.*named.*
cs_re:green:.*MINUTE MARK.*
cs_re:green:.*last message repeated.*
cs_re:green:.*logger.*
cs_re:blue:.*ntpd.*
# postfix log
colorscheme:postfix
cs_re:red:.*reject.*
cs_re:blue:.*cleanup.*
cs_re:blue:.*smtpd.*
cs_re:green:.*to=.*
cs_re:yellow:.*from=.*
cs_re:magenta:.*status=deferred.*
cs_re:magenta:.*spamd.*
cs_re:red:.*warning.*
cs_re:red:.*bounced.*
#snort log
colorscheme:snort
cs_re:green:.*Priority: 3.*
cs_re:yellow:.*Priority: 2.*
cs_re:red:.*Priority: 1.*
# Default colorschemes
scheme:postfix:/var/log/maillog
scheme:syslog:/var/log/messages
scheme:snort:/var/log/snort/alert
# wether to abbreviate filesizes to xKB/MB/GB
abbreviate_filesize:on
# Turn off mail check
check_mail:0
# timestring format for statusline
statusline_ts_format:%m/%d/%Y %H:%M
statusline_attrs:blue,white,reverse
# enable things with the xterm title bar
# %f changed file
# %h hostname
# %l system load
# %m "New mail" or nothing
# %u username
# %t date + time
titlebar:%u@%h %f (%t) [%l]'
if [ ! -f ~/.multitailrc ]; then
touch ~/.multitailrc
echo "-- created file ~/.multitailrc (was missing)"
fi
echo "$multitailconfig" > ~/.multitailrc
echo "############################################################"
echo "############################################################"
echo "Create bash alias 'log' for a faster usage"
bashaliases='#!/bin/bash
function logoutput() {
if [[ -z "$1" ]]; then
echo "please add at least one log file"
return;
fi
if [ $1 = "tom" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /usr/local/tomcat/logs/catalina.out
return
fi
if [ $1 = "tomdev" ]; then
if [ -f "/usr/local/tomcat_dev/logs/catalina.out" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /usr/local/tomcat_dev/logs/catalina.out
return
elif [ -f "/usr/local/tomcatdev/logs/catalina.out" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /usr/local/tomcat_dev/logs/catalina.out
return
else
echo "tomcat dev does not exist"
return
fi
fi
if [ $1 = "tomtest" ]; then
if [ -f "/usr/local/tomcat_test/logs/catalina.out" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /usr/local/tomcat_test/logs/catalina.out
return
elif [ -f "/usr/local/tomcattest/logs/catalina.out" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /usr/local/tomcattest/logs/catalina.out
return
else
echo "tomcat test does not exist"
return
fi
fi
multitail -n 1000 -M 1000 -CS log --mergeall $1 $2 $3 $4 $5 $6 $7 $8 $9
}
function logtomcatoutput() {
TOMCAT=$1
if [[ -z "$1" ]]; then
TOMCAT="tomcat"
fi
LOGFILE=$2
if [[ -z "$2" ]]; then
LOGFILE="catalina.out"
fi
if [ -f "/usr/local/$TOMCAT/logs/$LOGFILE" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /usr/local/$TOMCAT/logs/$LOGFILE
elif [ -f "/var/www/$TOMCAT/logs/$LOGFILE" ]; then
multitail -n 1000 -M 1000 -CS log --mergeall /var/www/$TOMCAT/logs/$LOGFILE
else
echo "Logfile does not exist here: /usr/local/$TOMCAT/logs/$LOGFILE or /var/www/$TOMCAT/logs/$LOGFILE"
fi
}
alias log=logoutput
alias logt=logtomcatoutput'
if [ ! -f ~/.bash_tail_aliases ]; then
touch ~/.bash_tail_aliases
echo "-- created file ~/.bash_tail_aliases (was missing)"
fi
echo "$bashaliases" > ~/.bash_tail_aliases
echo "############################################################"
echo "############################################################"
echo "As everyone likes a long history in his logs set the min_n_bufferlines to 1000"
sed -i -e 's/min_n_bufferlines:50/min_n_bufferlines:1000/g' /etc/multitail.conf
echo "############################################################"
echo "############################################################"
echo "Add the bash_tail_aliases reference to bashrc (if not exists)"
bashrc_content='if [ -f ~/.bash_tail_aliases ]; then
. ~/.bash_tail_aliases
fi'
if grep -q "bash_tail_aliases" ~/.bashrc; then
echo "-- bash_tail_aliases was already set"
else
echo "$bashrc_content" >> ~/.bashrc
echo "-- added bash_tail_aliases source (was missing)"
fi
echo "############################################################"
echo "############################################################"
echo "Add the bashrc reference to bash_profile (if not exists)"
bash_profile_content='if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi'
if grep -q "bashrc" ~/.bash_profile; then
echo "-- bashrc was already set"
else
echo "$bash_profile_content" >> ~/.bash_profile
echo "-- added bashrc source (was missing)"
fi
echo "############################################################"
echo "############################################################"
echo "Make sure to reload your bash after you've added those lines with: source ~/.bashrc"
echo "############################################################"
echo "############################################################"
echo "Everything set. Awesome. Try to call 'log', 'log tom', 'log tomtest', 'log tomdev', 'log ...logfiles'"
echo "############################################################"
echo "############################################################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment