You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

  1. #!/bin/sh
  2. # Shell script compatibility wrapper for /sbin/logread
  3. #
  4. # Copyright (C) 2019 Dirk Brenken <dev@brenken.org>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. logfile="/var/log/messages"
  21. if [ ! -f "${logfile}" ]
  22. then
  23. printf "%s\n" "Error: logfile not found!"
  24. exit 2
  25. fi
  26. usage()
  27. {
  28. printf "%s\n" "Usage: logread [options]"
  29. printf "%s\n" "Options:"
  30. printf "%5s %-10s%s\n" "-l" "<count>" "Got only the last 'count' messages"
  31. printf "%5s %-10s%s\n" "-e" "<pattern>" "Filter messages with a regexp"
  32. printf "%5s %-10s%s\n" "-f" "" "Follow log messages"
  33. printf "%5s %-10s%s\n" "-h" "" "Print this help message"
  34. }
  35. if [ -z "${1}" ]
  36. then
  37. cat "${logfile}"
  38. exit 0
  39. else
  40. while [ "${1}" ]
  41. do
  42. case "${1}" in
  43. -l)
  44. shift
  45. count="${1//[^0-9]/}"
  46. tail -n "${count:-50}" "${logfile}"
  47. exit 0
  48. ;;
  49. -e)
  50. shift
  51. pattern="${1}"
  52. grep -E "${pattern}" "${logfile}"
  53. exit 0
  54. ;;
  55. -f)
  56. tail -f "${logfile}"
  57. exit 0
  58. ;;
  59. -fe)
  60. shift
  61. pattern="${1}"
  62. tail -f "${logfile}" | grep -E "${pattern}"
  63. exit 0
  64. ;;
  65. -h|*)
  66. usage
  67. exit 1
  68. ;;
  69. esac
  70. shift
  71. done
  72. fi