test-0050.sh 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. . ./test-common.sh
  3. cleanup 50
  4. # ------------------------------- Test 50 ------------------------------------
  5. # test that hourly rotation works properly
  6. preptest test.log 50 1 0
  7. DATESTRING=$(/bin/date +%Y%m%d%H)
  8. NOW=$(/bin/date "+%Y-%-m-%-d-%-H" 2>/dev/null)
  9. HOURAGO=$(/bin/date "+%Y-%-m-%-d-%-H" --date "1 hour ago" 2>/dev/null)
  10. GNUDATE=$?
  11. # --force to trigger rotation
  12. $RLR test-config.50 --force
  13. checkoutput <<EOF
  14. test.log 0
  15. test.log-$DATESTRING 0 zero
  16. EOF
  17. # It should not rotate this hour again
  18. echo second > test.log
  19. rm -f test.log-$DATESTRING
  20. $RLR test-config.50
  21. checkoutput <<EOF
  22. test.log 0 second
  23. EOF
  24. if [ -f test.log.1 ]; then
  25. echo "file $file does exist!"
  26. exit 2
  27. fi
  28. if [ $GNUDATE = 0 ]; then
  29. # Simulate previous rotation by editing state file. This should overwrite
  30. # our previously rotated log
  31. sed -i "s,$NOW,$HOURAGO,g" state
  32. $RLR test-config.50
  33. checkoutput <<EOF
  34. test.log 0
  35. test.log-$DATESTRING 0 second
  36. EOF
  37. else
  38. echo "Does not have GNU Date, skipping part of this test"
  39. fi