home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 10.ddi / usr / lib / mail / vacation2 < prev   
Encoding:
Text File  |  1990-12-08  |  1.9 KB  |  89 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12. #ident    "@(#)/usr/lib/mail/vacation2.sl 1.1 4.0 12/08/90 17789 AT&T-USL"
  13. #
  14. # Second half of vacation(1).
  15. # When new message arrives, save it in MAILFILE and check any prior messages
  16. # from the same ORIGINATOR have been received. If so, exit. If not, record
  17. # ORIGINATOR in LOGFILE and send canned message from MSGFILE to ORIGINATOR.
  18. #
  19. PATH=/usr/bin
  20. USAGE="\07USAGE: ${0} -ooriginator [-m mailfile] [-M canned_msg_file] [-l logfile] [-F failsafe-path] [-d]"
  21. ORIGINATOR=
  22. MAILFILE=${HOME}/.mailfile
  23. LOGFILE=${HOME}/.maillog
  24. MSGFILE=/usr/share/lib/mail/std_vac_msg
  25. SILENT=NO
  26. FAILSAFE=
  27. DAILY=NO
  28. TMP=/tmp/.vac.$$
  29.  
  30. if [ ! -t 1 ]
  31. then
  32.     # stdout not a tty. Be as silent as possible.....
  33.     SILENT=YES
  34. fi
  35.  
  36. set -- `getopt o:m:M:l:F:d $*`
  37. if [ ${?} -ne 0 ]
  38. then
  39.     case "$SILENT" in
  40.         NO ) echo ${USAGE} 1>&2 ;;
  41.     esac
  42.     exit 1
  43. fi
  44.  
  45. for arg in ${*}
  46. do
  47.     case ${arg} in
  48.     -o)    ORIGINATOR=$2; shift 2;;
  49.     -m)    MAILFILE=$2; shift 2;;
  50.     -M)    MSGFILE=$2; shift 2;;
  51.     -l)    LOGFILE=$2; shift 2;;
  52.     -F)    FAILSAFE=$2; shift 2;;
  53.     -d)    DAILY=YES; shift;;
  54.     --)    shift; break;;
  55.     esac
  56. done
  57. if [ -z "${ORIGINATOR}" ]
  58. then
  59.     case "$SILENT" in
  60.         NO ) echo ${USAGE} 1>&2 ;;
  61.     esac
  62.     exit 1
  63. fi
  64.  
  65. case $DAILY in
  66.     YES ) MAILFILE=$MAILFILE.`date +%m%d` ;;
  67. esac
  68.  
  69. # append to the saved-mail file
  70. trap 'rm -f $TMP' 0 1 2 3 15
  71. if tee $TMP >> ${MAILFILE}
  72. then :
  73. else
  74.     if [ -n "$FAILSAFE" ]
  75.     then rmail "$FAILSAFE" < $TMP; exit 0
  76.     else exit 1
  77.     fi
  78. fi
  79.  
  80. # notify the originator
  81. if fgrep -x ${ORIGINATOR} ${LOGFILE} > /dev/null 2>&1
  82. then
  83.     :
  84. else
  85.     echo ${ORIGINATOR} >> ${LOGFILE} 2>/dev/null
  86.     ( cat ${MSGFILE} | mail ${ORIGINATOR} ) &
  87. fi
  88. exit 0
  89.