home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume28 / ureroute / part01 < prev    next >
Encoding:
Text File  |  1992-02-25  |  4.9 KB  |  165 lines

  1. Newsgroups: comp.sources.misc
  2. From: Bill.Campbell@celestial.com (Bill Campbell)
  3. Subject:  v28i073:  uureroute - Reroute HDB queued mail, Part01/01
  4. Message-ID: <1992Feb26.022837.27579@sparky.imd.sterling.com>
  5. X-Md4-Signature: 256a4af982c44cce4f3e1867694a06e3
  6. Date: Wed, 26 Feb 1992 02:28:37 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Bill.Campbell@celestial.com (Bill Campbell)
  10. Posting-number: Volume 28, Issue 73
  11. Archive-name: uureroute/part01
  12. Environment: perl, HDB, smail2.5
  13.  
  14. This is a Honey DanBer specific routine written in perl to reroute all 
  15. mail queued up for a specific host.  It needs to be run as "root" since 
  16. uucp will not allow itself to remove others requests.
  17.  
  18. Bill Campbell
  19. --------------------
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of shell archive."
  27. # Contents:  uureroute
  28. # Wrapped by bill@camco1 on Tue Feb 11 07:44:10 1992
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'uureroute' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'uureroute'\"
  32. else
  33. echo shar: Extracting \"'uureroute'\" \(3075 characters\)
  34. sed "s/^X//" >'uureroute' <<'END_OF_FILE'
  35. X:
  36. X#!/usr/local/bin/perl
  37. Xeval ' exec /usr/local/bin/perl $0 "$@" '
  38. X    if $running_under_some_shell;
  39. X    shift if(join("", @ARGV) eq ""); # Xenix Kludge
  40. X
  41. X# $Header: /u/usr/cvs/mail/uureroute,v 1.3 91/10/08 09:01:21 src Exp $
  42. X# $Date: 91/10/08 09:01:21 $
  43. X# @(#) $Id: uureroute,v 1.3 91/10/08 09:01:21 src Exp $
  44. X# $Log:    uureroute,v $
  45. X# Revision 1.3  91/10/08  09:01:21  src
  46. X# ----------------------------------------------------------------------
  47. X#     1.    Rewritten in perl
  48. X#       2.    Add -v option for debugging.
  49. X# 
  50. X# Revision 1.2  91/10/07  23:57:42  root
  51. X# 1.    Fix mail program path.
  52. X# 2.    Truncate directory name to 7 characters
  53. X#
  54. X#    uureroute.sh host
  55. X#
  56. X#  This is a Honey DanBer specific routine to reroute all mail queued up
  57. X#  for a specific host.  It needs to be run as "root" since uucp will not
  58. X#  allow itself to remove others requests.
  59. X#
  60. X
  61. X( $progname = $0 ) =~ s!.*/!!; # save this very early
  62. X
  63. X$USAGE = "
  64. X#   Reroute uucp mail
  65. X#
  66. X#   Usage: $progname [-v] host [host...]
  67. X#
  68. X# Options   Argument    Description
  69. X#   -v                  Verbose (doesn't execute /bin/sh)
  70. X#
  71. X";
  72. X
  73. Xsub usage {
  74. X    die join("\n",@_) .
  75. X    "\n$USAGE\n";
  76. X}
  77. X
  78. Xdo "getopts.pl";
  79. X
  80. X&usage("Invalid Option") unless do Getopts("vV");
  81. X
  82. X$verbose = ( $opt_v ? '-v' : () );
  83. X$suffix = ( $verbose ? '' : $$ );
  84. X
  85. X$\ = "\n";    # use newlines as separators.
  86. X
  87. X&usage("No system specified") if ($#ARGV < 0);
  88. X
  89. Xif(! $verbose ) {
  90. X    open(SH, "| /bin/sh");
  91. X    select(SH);
  92. X}
  93. Xprint "set -ex";
  94. Xwhile($system = shift) {
  95. X    $directory = '/usr/spool/uucp/' . substr($system, 0, 7);
  96. X    if( ! -d $directory ) {
  97. X        print STDERR "$progname: nothing queued for $system";
  98. X        next;
  99. X    }
  100. X    open(UUSTAT, "uustat -s $system|");
  101. X
  102. X    line: while (<UUSTAT>) {
  103. X        chop;    # strip record separator
  104. X        @Fields = split(' ', $_, 9999);
  105. X        if (/^[a-z]/) {
  106. X            $jobid        = $Fields[0];
  107. X            $datafile    = $Fields[6];
  108. X        }
  109. X        else {
  110. X            if ($Fields[4] ne 'rmail') {
  111. X                next line;
  112. X            }
  113. X            $cmd = '/bin/smail -R';    # smail 2.5 rabid rerouter
  114. X            splice(@Fields, 0, 5);    # remove first 5 elements
  115. X            while($addr = shift(@Fields)) {
  116. X                $addr =~ s/@.*//;    # drop domain part
  117. X                $cmd .= " $system!$addr";
  118. X            }
  119. X            $cmd .= " < $directory/$datafile && uustat -k $jobid";
  120. X            print $cmd;
  121. X        }
  122. X    }
  123. X    close(UUSTAT);
  124. X}
  125. Xclose(SH) unless($verbose);
  126. X__END__
  127. X>From: mattc@ncr-sd.SanDiego.NCR.COM (Matt Costello)
  128. X>Newsgroups: comp.mail.uucp
  129. X>Subject: Re: Rerouting spooled UUCP mail (HDB+smail)
  130. X>Message-ID: <3038@ncr-sd.SanDiego.NCR.COM>
  131. X>Date: 27 Nov 90 19:04:24 GMT
  132. X>References: <17525@netcom.UUCP>
  133. X>Reply-To: mattc@ncr-sd.SanDiego.NCR.COM (Matt Costello)
  134. X>Organization: NCR Corporation, Rancho Bernardo
  135. X>Lines: 61
  136. X
  137. XHere is another shell script to reroute mail queued up in an outgoing
  138. XUUCP spool directory.  It performs the same function as the script posted
  139. Xby Gordon Moffett <gam@netcom.UUCP> but it uses "uustat -s system" so
  140. Xit doesn't mess around in the bowels of UUCP.  This makes it a whole lot
  141. Xsimpler and safer.  Just change the shell procedure definition for mail()
  142. Xto match what your MTA needs.
  143. X
  144. X-- 
  145. XMatthew Costello       <Matthew.Costello@SanDiego.NCR.COM>
  146. X+1 619 485 2926        uunet!ncrlnk!ncr-sd!mattc
  147. END_OF_FILE
  148. if test 3075 -ne `wc -c <'uureroute'`; then
  149.     echo shar: \"'uureroute'\" unpacked with wrong size!
  150. fi
  151. chmod +x 'uureroute'
  152. # end of 'uureroute'
  153. fi
  154. echo shar: End of shell archive.
  155. exit 0
  156.  
  157. Bill
  158. --
  159. INTERNET:  bill@Celestial.COM   Bill Campbell; Celestial Software
  160. UUCP:        uunet!camco!bill   6641 East Mercer Way
  161. FAX:           (206) 232-9186   Mercer Island, WA 98040; (206) 947-5591
  162.  
  163.  
  164. exit 0 # Just in case...
  165.