prune_logs_compress 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/ksh
  2. #
  3. # prune_logs
  4. #
  5. ########################################################################
  6. #set -x
  7. ##########################################################################
  8. #
  9. # Script setup: THIS NEEDS TO BE FIRST
  10. #
  11. SCRIPTS_DIR="`dirname $0`"
  12. if [ "" = "$SCRIPTS_DIR" ]; then
  13. SCRIPTS_DIR=/project/dt/scripts
  14. fi
  15. if [ ! -f $SCRIPTS_DIR/script_setup.ksh ]; then
  16. print -u2 "$PRG: File '$SCRIPTS_DIR/script_setup.ksh' NOT found!"
  17. print -u2 "$PRG: Exiting ..."
  18. exit 1
  19. fi
  20. . $SCRIPTS_DIR/script_setup.ksh
  21. ##########################################################################
  22. ##########################################################################
  23. #
  24. # Script specific global variables
  25. #
  26. ##########################################################################
  27. ##########################################################################
  28. DEBUG=""
  29. FIND_OPTIONS=""
  30. OUTFILE="/dev/null"
  31. PATHNAME_LIST=""
  32. PROG_NAME="`basename $0`"
  33. usage ()
  34. {
  35. cat <<eof
  36. USAGE: $PROG_NAME [options] pathname_list
  37. [-debug]
  38. # Debugging output
  39. [-atime +ndays]
  40. [-ctime +ndays]
  41. [-mtime +ndays]
  42. # These flags are passed directly to find to identify
  43. # which files and directories should pass the test for
  44. # deletion.
  45. [-h | -? | -help]
  46. # Print usage and exit
  47. pathname_list
  48. # List of directories to be searched for out-of-date
  49. # log files
  50. $PROG_NAME uses find to search all the directories listed in
  51. pathname_list for files and subdirectories which are out-of-date
  52. as specified by the -atime, -ctime, and -mtime flags deleting
  53. any so identified.
  54. eof
  55. }
  56. #
  57. # Do command-line processing
  58. #
  59. while [ $# -gt 0 ]; do
  60. case $1 in
  61. -debug)
  62. DEBUG="echo"
  63. shift 1 ;;
  64. -atime | -ctime | -mtime)
  65. if [ $# -lt 2 ]; then
  66. print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
  67. do_exit 1
  68. fi
  69. FIND_OPTIONS="$FIND_OPTIONS $1 $2 "
  70. shift 2 ;;
  71. -h | "-?" | -help)
  72. usage $PROG_NAME;
  73. do_exit 1 ;;
  74. *)
  75. PATHNAME_LIST="$PATHNAME_LIST $1"
  76. shift 1;;
  77. esac
  78. done
  79. #
  80. # Clean up temporary files and exit
  81. #
  82. $DEBUG find $PATHNAME_LIST -depth -name '*' $FIND_OPTIONS -exec gzip -f {} ";" > $OUTFILE 2>&1
  83. do_exit 0