apachelog 809 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. if [[ "$1" = "" ]];then
  3. apachelog more;
  4. else
  5. site=$1;
  6. shift;
  7. if [[ "$1" == "" ]];then
  8. t=$site;
  9. site="";
  10. path="/var/log/apache2/error.log";
  11. else
  12. t=$1;
  13. shift;
  14. path="/var/log/apache2/$site.error.log";
  15. fi;
  16. case "$t" in
  17. search)
  18. cat $path | grep "$@";
  19. ;;
  20. ignore)
  21. cat $path | grep -v "$@";
  22. ;;
  23. tail)
  24. if [[ "$@" == "" ]];then
  25. tail -f $path;
  26. else
  27. tail --lines="$@" $path;
  28. fi;
  29. ;;
  30. more)
  31. more $path;
  32. ;;
  33. flush)
  34. echo "" > $path;
  35. ;;
  36. sites)
  37. ls /var/log/apache2/*.error.log | awk '{print gensub(/\.error\.log$/, "", "g", gensub(/^.*\//, "","g"))}';
  38. ;;
  39. *)
  40. echo "Usage: $0 <site> [{search|ignore|tail|more|flush|sites} <params>]";
  41. exit 1;
  42. esac;
  43. fi;