syslog03 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #! /bin/sh
  2. # Copyright (c) International Business Machines Corp., 2002
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. # the GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. # 12/05/02 Port to bash -Robbie Williamson <robbiew@us.ibm.com>
  18. # 02/05/03 Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
  19. # fixed bugs.
  20. # 07/27/05 Michael Reed <mreedltp@vnet.ibm.com>
  21. # Made changes to account for the replacement of syslogd
  22. # with syslog-ng on SLES
  23. #
  24. ##################################################################
  25. # case 3: Do openlog(), log the messages and see whether #
  26. # ident string is prepended to the message. #
  27. # #
  28. # syslog.conf should contain: #
  29. # *.crit /usr/adm/critical #
  30. # daemon.info /usr/spool/adm/syslog #
  31. ##################################################################
  32. . syslog-lib.sh || exit 1
  33. syslog_case3()
  34. {
  35. # Create the configuration file specific to this test case.
  36. case "$CONFIG_FILE" in
  37. /etc/syslog.conf|/etc/rsyslog.conf)
  38. echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
  39. echo "daemon.info /var/log/messages" >> $CONFIG_FILE
  40. ;;
  41. /etc/syslog-ng/syslog-ng.conf)
  42. echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
  43. echo " " >> $CONFIG_FILE
  44. echo "# Added for syslog testcase" >> $CONFIG_FILE
  45. echo "filter f_syslog_daemon { level(info) and facility(daemon); }; " >> $CONFIG_FILE
  46. echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
  47. echo "log { source(src); filter(f_syslog_daemon); destination(syslog-messages);};" >> $CONFIG_FILE
  48. ;;
  49. esac
  50. restart_syslog_daemon
  51. # Grep for the ident prefix: SYSLOG_CASE3 in the log file.
  52. if [ -e /var/log/messages ]; then
  53. oldvalue4=`grep -c "SYSLOG_CASE3" /var/log/messages`
  54. else
  55. oldvalue4=0
  56. fi
  57. if ! syslogtst 3 2>/dev/null; then
  58. cleanup 1
  59. fi
  60. sleep 2
  61. # check if /var/log/messages exists
  62. if [ ! -e /var/log/messages ]; then
  63. tst_resm TBROK "/var/log/messages no such log file"
  64. cleanup 1
  65. fi
  66. newvalue4=`grep -c "SYSLOG_CASE3" /var/log/messages`
  67. if [ "x$(( $newvalue4 - $oldvalue4 ))" != x1 ]; then
  68. status_flag=1
  69. fi
  70. }
  71. tst_resm TINFO "Do openlog(), log the messages and see whether"
  72. tst_resm TINFO "ident string is prepended to the message."
  73. setup
  74. syslog_case3
  75. cleanup ${status_flag:=0}