Posted By

XtreamIT on 12/21/12


Tagged

Bash linux log shellscript


Versions (?)

Multiple logs


 / Published in: Bash
 

  1. #!/bin/bash
  2. #
  3. # Show multiple logs with matching colorthemes, @2012 XtreamIT
  4. #
  5. # Written by Jonas Persson <[email protected]>
  6. # Dependencies: Multitail <http://www.vanheusden.com/multitail/>
  7. # Usage: multiLog [path]
  8.  
  9. # For future remote logging feature try: multitail -l 'ssh user@host1 "tail -f /path/to/log/file"' -l 'ssh user@host2 "tail -f /path/to/log/file"'
  10.  
  11. # Variables
  12. path=$1
  13. exe_str=""
  14.  
  15. # Functions
  16. function getColorScheme()
  17. {
  18. case ${1#*.} in
  19. "access.log") colortheme="-cS apache";;
  20. "error.log") colortheme="-cS apache_error";;
  21. *) colortheme="-cS syslog";;
  22. esac
  23.  
  24. echo $colortheme # Use echo to return string cause bash by defaul only can return intigers
  25. }
  26.  
  27. # Main
  28. if [ $# -ne 1 ] ; then
  29. echo "Usage - $0 <path></path>"
  30. exit 1
  31. fi
  32.  
  33. if [ -d $path ] ; then
  34. cd $path
  35. for log_file in * ; do
  36. colortheme=$(getColorScheme $log_file)
  37. exe_str="$exe_str $colortheme $log_file"
  38. done
  39. multitail $exe_str
  40. else
  41. echo "Path not valid"
  42. exit 1
  43. fi
  44.  
  45. exit 0

Report this snippet  

You need to login to post a comment.