cron_scripts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/ksh
  2. #
  3. # $TOG: cron_scripts /main/11 1999/04/26 11:42:51 mgreess $
  4. #
  5. # This script is run on all of the systems where an automated
  6. # X build will occur.
  7. #
  8. # The main benefit of using this script is that if the type of build
  9. # that needs to be done changes, (e.g. a clean build is needed
  10. # instead of an incremental build), then only this file needs to be
  11. # changed and none of the crontabs need to be changed.
  12. #
  13. #############################################################################
  14. #
  15. # The following trap is needed because of a bug in the UXP (Fujitsu)
  16. # version of ksh.
  17. #
  18. trap 'echo "Trapped signal USR1"' USR1
  19. ##########################################################################
  20. ##########################################################################
  21. #
  22. # Script specific global variables
  23. #
  24. ##########################################################################
  25. ##########################################################################
  26. SCRIPTS_DIR="`dirname $0`"
  27. if [ "" = "$SCRIPTS_DIR" ]; then
  28. SCRIPTS_DIR=/project/dt/scripts
  29. fi
  30. if [ "" = "$ADMIN_CRON" ]; then
  31. ADMIN_CRON=/project/dt/admin/cron
  32. fi
  33. if [ "" = "$CRON_DATABASE" ]; then
  34. CRON_DATABASE=$ADMIN_CRON/crondb
  35. fi
  36. DEBUG=""
  37. MAIL_TO=""
  38. PROG_NAME="`basename $0`"
  39. ##########################################################################
  40. usage ()
  41. {
  42. cat <<eof
  43. USAGE: $PROG_NAME
  44. [-debug]
  45. # Debugging output
  46. [{-db | -database} <cron_database_file>]
  47. # Specify the cron database
  48. # Default: $CRON_DATABASE
  49. [{-m | -mail} <email>]
  50. # Specify an alternate email recipient for unexpected output.
  51. # Default: $CDE_MAIL_ALIAS or $X_MAIL_ALIAS
  52. [{-sd | -script_dir} <directory>]
  53. # Specify an alternate directory for required files.
  54. # Default: $SCRIPTS_DIR/
  55. [-h | -? | -help]
  56. # Print usage and exit
  57. eof
  58. }
  59. ##########################################################################
  60. while [ $# -gt 0 ]; do
  61. case $1 in
  62. -debug) DO_DEBUG="True"
  63. DEBUG="echo"
  64. shift 1 ;;
  65. -db | -database) CRON_DATABASE=$2;
  66. shift 2 ;;
  67. -m | -mail) MAIL_TO=$2;
  68. shift 2 ;;
  69. -sd | -script_dir) SCRIPTS_DIR=$2;
  70. export SCRIPTS_DIR;
  71. shift 2 ;;
  72. -h | "-?" | -help | *) usage $PROG_NAME;
  73. exit 1;
  74. esac
  75. done
  76. #
  77. # Capture all of the spurious output to stdout and stderr
  78. #
  79. LOGFILE=/tmp/$$.log
  80. exec > $LOGFILE 2>&1
  81. #
  82. # TRACE should be passed into the script as an environment variable
  83. # i.e., TRACE=true cron_scripts ...
  84. #
  85. if [ "" != "$TRACE" ]; then
  86. echo Debugging: $DO_DEBUG
  87. echo Cron Database: $CRON_DATABASE
  88. echo Mail Recipient: $MAIL_TO
  89. echo Scripts Dir: $SCRIPTS_DIR
  90. set -x
  91. fi
  92. ##########################################################################
  93. #
  94. # Script setup: Do this after the command line parsing to pick up
  95. # an alternate setting of SCRIPTS_DIR
  96. #
  97. if [ ! -f $SCRIPTS_DIR/script_setup.ksh ]; then
  98. print -u2 "$PRG: File '$SCRIPTS_DIR/script_setup.ksh' NOT found!"
  99. print -u2 "$PRG: Exiting ..."
  100. exit 1
  101. fi
  102. . $SCRIPTS_DIR/script_setup.ksh
  103. do_check_file $CRON_DATABASE -f "NOT found"
  104. COMM="#"
  105. DAY="`date +%a`"
  106. HOST="`uname -n | sed '/\./s/\..*//'`"
  107. HOUR="`date +%H`"
  108. cat $CRON_DATABASE | while read LINE; do
  109. ENTRY="`echo $LINE | grep -v $COMM | grep $HOST | grep $DAY | grep $HOUR`"
  110. EDAY="`echo $ENTRY | awk '{ print $1 }'`"
  111. EHOUR="`echo $ENTRY | awk '{ print $2 }'`"
  112. EHOST="`echo $ENTRY | awk '{ print $3 }'`"
  113. EVIEW="`echo $ENTRY | awk '{ print $4 }'`"
  114. ECOMMAND="`echo $ENTRY | awk '{ for (i=5; i<=NF; i++) printf(\"%s \",$i) }'`"
  115. if [ -n "$ENTRY" -a "$HOUR" = "$EHOUR" ]; then
  116. if [ "none" = "$EVIEW" ]; then
  117. $DEBUG $ECOMMAND
  118. else
  119. $DEBUG $CLEAR_CASE_TOOL setview -exec "$ECOMMAND" $EVIEW
  120. fi
  121. fi
  122. done
  123. if [ -s $LOGFILE ]; then
  124. if [ "" = "$MAIL_TO" ]; then
  125. if [ "`basename $CRON_DATABASE`" = "trw.crondb" ]; then
  126. MAIL_TO=$TRW_MAIL_ALIAS
  127. elif [ "`basename $CRON_DATABASE`" = "cde.crondb" ]; then
  128. MAIL_TO=$CDE_MAIL_ALIAS
  129. elif [ "`basename $CRON_DATABASE`" = "x.crondb" ]; then
  130. MAIL_TO=$X_MAIL_ALIAS
  131. else
  132. MAIL_TO=$CDE_MAIL_ALIAS
  133. fi
  134. fi
  135. mailx -s "Warning: unexpected cron output" $MAIL_TO < $LOGFILE
  136. fi
  137. rm -f $LOGFILE