home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2157 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  5.7 KB

  1. From: gam@netcom.UUCP (Gordon Moffett)
  2. Newsgroups: alt.sources,comp.mail.uucp
  3. Subject: Rerouting spooled UUCP mail (HDB+smail)
  4. Message-ID: <17525@netcom.UUCP>
  5. Date: 27 Nov 90 03:20:59 GMT
  6.  
  7. My query for a shell script to respool UUCP mail for a site gone dead
  8. had gotten a few responses, but all refering to Lenny Tropiano's
  9. "uureroute.c" posted recently, which expected *you* to provide the new
  10. path names, *you* to provide the UUCP job names, etc ....  A computer
  11. should be expected to do better than that :-)!
  12.  
  13. I had sent a copy of this shell script I was speaking of to our
  14. neighbor, amdahl, when I had originally gotten it, and got it back from
  15. them -- here it is.  You just recalculate your pathalias database, run
  16. this shell script for a given site, and see the mail get rerouted to
  17. new paths.  The usage is quite simple:  "reroute <sitename>", like
  18. "reroute claris" or whatever.  It expects to be run by 'root', and uses
  19. the id(1) program to determine that.
  20.  
  21. I call it "reroute" the author called it "nukeq", you can name it
  22. whatever you like.
  23.  
  24. Here is the author's original message.  Note the caveats!  But I have used it
  25. several times and it works beautifully.  (There was a bug in the reference
  26. to the $user environment variable which is fixed here).
  27.  
  28. When he talks about "smail" he is refering to smail 2.5.  But I have
  29. used it with smail 3.1 without any problems.  Smail 3.1 appears to ignore
  30. the -R flag, perhaps it should be taken out if you're running 3.1
  31.  
  32. Subject: Re: Rerouting spooled UUCP mail?
  33. Date: 11 Jan 90 20:18:08 EST (Thu)
  34. From: uunet!wang.COM!fitz (Tom Fitzgerald)
  35.  
  36. > I need a tool to take UUCP jobs queued up for one site (which is dead)
  37. > and move them to another site's UUCP queue.
  38.  
  39. Here's what I use.  It makes some assumptions:
  40.  
  41. - You're using HDB.  If not, you'll have to screw with the filename
  42.   pattern matching and directories.
  43.  
  44. - You're using SMAIL.  If not, you'll have to have some other mailer that
  45.   accepts header lines in the message without modifying them, and you'll
  46.   have to find some way of simulating SMAIL's -R (aggressive-rerouting)
  47.   option.
  48.  
  49. - You've already rebuilt the 'paths' file so that the dead node is missing
  50.   from all paths.
  51.  
  52. - You're logged in as root (needless to say).
  53.  
  54. It's also got these flaky aspects:
  55.  
  56. - It's dangerous as hell.  I wrote it, and it scares me.  Save a copy
  57.   of all mail, and make sure the result is what you wanted before you
  58.   let a uucico start up.
  59.  
  60. - If any mail is queued for a user on the dead system (or for a user
  61.   that can _only_ be reached via the dead system) it will not be rerouted.
  62.  
  63. - Results in a doubled "Recieved:" line in the header.
  64.  
  65. - More flakinesses are mentioned in the script itself.
  66.  
  67. If you haven't given up yet, here it is.  Good luck.
  68.  
  69. -----------------------------------------------------------------------------
  70. # Remail all of the mail queued for a particular system.  Run as
  71. #
  72. # nukeq <sysname>
  73. #
  74. # Does nothing unless the paths files have been rebuilt so that all
  75. # final destinations in the mail messages are now reached through a
  76. # different neighbor.  Otherwise mail will just be requeued for the
  77. # same system again.
  78. #
  79. # Doesn't fix the requestor field in the new X file, so errors in mailing
  80. # further along the line will probably be returned to the person who ran
  81. # nukeq rather then the person who originally sent the mail.
  82. #
  83. # The destinations are aggressively rerouted on the assumption that the
  84. # old path is irrelevant to the new first-hop.  This may result in mail
  85. # sent to an incorrect system with the same name as the correct system.
  86. #
  87. # If uucico starts up while this thing is running, the world will come
  88. # to an end.
  89.  
  90.  
  91. if [ `id|sed 's/^uid=\([0-9]*\).*$/\1/'` -ne 0 ]
  92. then
  93.     echo Not superuser, no can do.
  94.     exit
  95. fi
  96.  
  97. if [ $# -ne 1 ]
  98. then
  99.     echo Need a system name
  100.     exit
  101. fi
  102.  
  103. sysname=$1
  104.  
  105. cd /usr/spool/uucp/$sysname
  106.  
  107. for cfile in C.*
  108. do
  109.     (
  110.         echo Doing C-file $cfile
  111.  
  112.         # For each C-file
  113.         # Grab the line describing the D file
  114.  
  115.         read type source dest sender opts data mode notify || {
  116.             echo $cfile is empty, skipping...
  117.             continue
  118.         }
  119.  
  120.         if [ "$type" != "S" -o "$source" != "$data" \
  121.           -o "$sender" != "$notify" -o "$opts" != "-" ]
  122.         then
  123.             echo $cfile has invalid line 1, skipping...
  124.             continue
  125.         fi
  126.  
  127.         case $dest in
  128.             D.*)    ;;
  129.             *)    echo $cfile line 1 isn\'t a Dfile, skipping...
  130.                 continue
  131.                 ;;
  132.         esac
  133.  
  134.         dfile=$source
  135.         echo D-file is $dfile
  136.  
  137.         # Grab the line describing the X file
  138.         read type source dest sender opts data mode notify || {
  139.             echo $cfile missing line 2, skipping...
  140.             continue
  141.         }
  142.  
  143.         if [ "$type" != "S" -o "$source" != "$data" \
  144.           -o "$sender" != "$notify" -o "$opts" != "-" ]
  145.         then
  146.             echo $cfile has invalid line 2, skipping...
  147.             continue
  148.         fi
  149.  
  150.         case $dest in
  151.             X.*)    ;;
  152.             *)    echo $cfile line 2 isn\'t an Xfile, skipping...
  153.                 continue
  154.                 ;;
  155.         esac
  156.  
  157.         xfile=$source
  158.         echo X-file is $xfile
  159.  
  160.         # Make sure the X-file was the last line in the C-file
  161.         read type
  162.         if [ -n "$type" ]
  163.         then
  164.             echo $cfile has more than 2 lines, skipping...
  165.             continue
  166.         fi
  167.  
  168.         # Read the xfile looking for the destinations
  169.         dests=`egrep '^C rmail ' < $xfile | sed 's/^C rmail //'`
  170.  
  171.         if [ `echo $dests | wc -w` -eq 0 ]
  172.         then
  173.             echo $cfile isn\'t an rmail job, skipping...
  174.             continue
  175.         fi
  176.  
  177.         # Build newdests, which is the same as dests for users on
  178.         # machines other than the one being nuked, and is $sysname!user
  179.         # for users on the same system (this will result in mail being
  180.         # queued back onto the same system again).
  181.  
  182.         newdests=''
  183.         for user in $dests
  184.         do
  185.             if [ -n "`echo $user | grep !`" ]
  186.             then
  187.                 newdests="$newdests $user"
  188.             else
  189.                 newdests="$newdests $sysname!$user"
  190.             fi
  191.         done
  192.  
  193. #        echo Rerouting to $newdests
  194.  
  195.         # Re-send the mail, using aggressive rerouting
  196.         smail -R -v $newdests < $dfile
  197.  
  198.         # And kill off the old message
  199.         rm $cfile $dfile $xfile
  200.         echo Done
  201.     ) < $cfile
  202. done
  203. exit
  204.