home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / apollo / 3453 < prev    next >
Encoding:
Internet Message Format  |  1992-09-03  |  14.7 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hplabs!ucbvax!PAN.SSEC.HONEYWELL.COM!schumack
  2. From: schumack@PAN.SSEC.HONEYWELL.COM (Ken Schumack)
  3. Newsgroups: comp.sys.apollo
  4. Subject: re: File-splitter for email
  5. Message-ID: <9209032029.AA14664@pan.ssec.honeywell.com>
  6. Date: 3 Sep 92 20:29:36 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: world
  9. Organization: The Internet
  10. Lines: 486
  11.  
  12.  
  13.  
  14. > <<forwarded message>>
  15. > In article <1992Aug28.172903.27023@hns.com> rtaylor@hns.com (Randy Taylor) writes:
  16. > >
  17. > >A freind of mine is looking for a file splitter
  18. > >for email.  He is transmitting 100k to 1 Meg
  19. > >ASCII files and it seems that most mail programs
  20. > >can handle a max "chuck" size of 50 k.
  21. > >
  22. > Have a look at   split
  23. > It should do what you want.
  24. >    Andy
  25.  
  26. For what it's worth you might also take a look at the following routine:
  27. Example of use...
  28. To send a directory/file(s) type:
  29.  
  30. mailsplit -l 3000 userSendingTo BigFileName
  31.  
  32. to recover type: 
  33.  
  34. mailjoin BigFileName
  35.  
  36. -------------------------------------------------------------------------------
  37. Ken Schumack                              phone:612-541-2743
  38. Honeywell(Solid State Electronics Center) fax  :612-541-2504
  39. MN14-4B80                                 email:schumack@pan.ssec.honeywell.com
  40. -------------------------------------------------------------------------------
  41.  
  42.  
  43. #!/bin/sh
  44. ##############################################################################
  45. # These commands and paths should be configured for your machine/site
  46. BASENAME=/usr/bin/basename
  47. TEST=/bin/test
  48. CAT=/bin/cat
  49. RM=/bin/rm
  50. SPLIT=/usr/bin/split
  51. SLEEP=/usr/bin/sleep         # Sleep command
  52. TA=/bin/tar                  # Archive command (assumed here to be in search path!)
  53. CO=/usr/ucb/compress         # Default compress command  (assumed to be in search path!)
  54. MA=/usr/ucb/Mail             # Default Mail program
  55. UU=/usr/bin/uuencode         # uuencode command (assumed here to be in search path!)
  56. CB=16                        # Default number of bits to use in compress
  57. CF="-b 16"                   # Default compress command line flag(s)
  58. MS=Subj                      # Mailer Subject line flag
  59. DE=0                         # Default delay time between sending pieces
  60. TD=/tmp                      # Default temporary directory for storing temp files
  61. DB=5                         # Default debugging level
  62. ##############################################################################
  63. #
  64. # mailsplit:  package, transmit, re-assemble unix directories via e-mail
  65. #
  66. # @(#)mailsplit.SH    2.6    88/08/20       M F Wyle
  67. # Syntax corrections to joinr script  90/03/06
  68. # Rev 2.7 90/11/16  K V Schumack
  69. #   updated to work w/ Mentor send, added variable for test
  70. # Rev 2.8  replaced joinr w/ mailjoin
  71. ##############################################################################
  72. # You might want to change these, but it's not likely.
  73.  
  74. ME=`$BASENAME $0`   # Program (my) name
  75. LI=700              # Default number of lines for split-up pieces
  76. CM="$0 $*"          # Command line
  77. VE="2.8"            # Version of this program
  78. MF=""               # Default Mailer flags
  79. IJ="true"           # Flag which signals if joinr script should be prepended
  80. TM=false            # Default test Mode flag (If set, don't do anything)
  81. T1=$TD/1sp$$        # Default temp file for output of tar, compress
  82. T2=$TD/2sp$$        # Default temp file for uuencoded output
  83. T3=$TD/3sp$$        # Default temp file prefix for split pieces
  84. T4=$TD/4sp$$        # a copy of mailjoin
  85. ##############################################################################
  86.  
  87. # You do NOT want to change these variables or their initial values!
  88.  
  89. RA=all              # Default range of pieces to send
  90. FC=0                # File Count
  91. ne="FL=$FL' '"      # Next command in parser
  92. SU="_default_"      # Default Subject is first file or dir sent
  93. FL=""               # Initialize file list
  94. TO=""               # Initialize recipient
  95. umask 0             # Important for writing reading files created!
  96.  
  97. # Human Factors Law Number 4:  
  98. # "Upon startup, thou shalt tell the user where he is and how to quit."
  99. #           -Ben Schneiderman-
  100.  
  101. echo " " 1>&2
  102. echo "$ME version $VE" 1>&2
  103. echo "Original coding (C) 1988  M F Wyle" 1>&2
  104. echo " " 1>&2
  105.  
  106. ##############################################################################
  107. # Read beyond here at your own risk; you've entered... The hacker zone...
  108. # Parse the command line for recipient, options, flags, files, dirs:
  109.  
  110. for AR in $* ; do
  111.   case $AR in
  112.     -C  ) ne="CO=" ;;
  113.     -D  ) ne="TD=" ;;
  114.     -M  ) ne="MF=" ;;
  115.     -N  ) IJ="false" ;;
  116.     -T  ) ne="TA=" ;;
  117.     -V  ) DB=9     ;;
  118.     -b  ) ne="CB=" ;;
  119.     -d  ) ne="DE=" ;;
  120.     -l  ) ne="LI=" ;;
  121.     -m  ) ne="MA=" ;;
  122.     -n  ) TM=true  ;;
  123.     -r  ) ne="RA=" ;;
  124.     -s  ) ne="SU=" ;;
  125.     -t  ) TM=true ;;
  126.     -v  ) echo "$ME version $VE" ;  exit 0 ;;
  127.     -x* ) DB=`echo $AR | cut -c3` ; DB=${DB:-0} ;;
  128.     -u  ) ne="UU=" ;;
  129.     -*  ) echo " " ; echo "Bad flag for $ME": $AR
  130.           echo "Usage:    $ME  [<options>] <mailpath> <file(s)>"
  131.           echo "Example:  $ME  werner@utastro.uucp ./casetool"
  132.           echo " "
  133.           exit 0  ;;
  134.     *   ) eval $ne"$AR" ; ne='FL=$FL" "' ;;
  135.   esac
  136. done
  137. case $# in
  138.   0 | 1 )
  139.     echo " "
  140.     echo "Usage:    $ME  [<options>] <mailpath> <file(s)>"
  141.     echo "Example:  $ME  werner@utastro.uucp CaseTool"
  142.     echo " "
  143.     exit 0  ;;
  144. esac
  145. set $FL
  146. TO=$1
  147. case $SU in
  148.   _default_ ) SU=$2 ;;
  149. esac
  150.  
  151. case $DB in
  152.   8|9) set -x ;;
  153. esac
  154.  
  155. # create a copy of mailjoin in /tmp:
  156. cat >$T4 <<'MAILJOIN!END'
  157. ----------------- start cut here for mailjoin routine ---------------------------
  158. #!/bin/csh -f
  159. #
  160. # mailjoin - Extract and glue together mailsplit transmissions (c)KSchumack
  161. # 1.0 : 05/05/92 : K.Schumack  needs /usr/ucb; schumack@pan.ssec.honeywell.com
  162. # 1.1 : 05/06/92 : K.Schumack  modified nawk script to run faster, and
  163. #                              only take the 1st complete object it finds
  164. # 1.2 : 05/07/92 : K.Schumack  cat the mentor mail msgs in reverse order
  165. #                              to get only the latest object. Added "V" variable
  166. # 1.3 : 09/02/92 : K.Schumack  make educated guesses for mail type and nawk option
  167. ############################################################################
  168. # These commands and paths should be configured for your machine/site
  169. #
  170. set path=(/usr/ucb /usr/bin /bin $path)
  171. ##
  172. #set MAILS=~/mail  # "~/mail" for Mentor mail; "/usr/spool/mail/$user" for UNIX mail
  173. #make educated guess at to what type of mail is used...
  174. if (-d ~/mail) then
  175.     set MAILS=~/mail  # "~/mail" for Mentor mail
  176. else
  177.     set MAILS="/usr/spool/mail/$user" # for UNIX mail
  178. endif
  179. ##
  180. #set V             #!! use this line if your nawk uses "var=value" (check man page)
  181. #set V="-v"        #!! use this line if your nawk uses "-v var=value" (check man page)
  182. #some awks use -v look into man page to see which to use...
  183. set V=`man nawk | nawk 'BEGIN{a=""} {if($0~"-v ")a="-v"} END{print a}'` 
  184. #
  185. ############################################################################
  186. set REV="1.3 09/03/92 (c) K.Schumack"
  187. set DatE=`/bin/date` 
  188. set TimE=$DatE[4]
  189. set tempFile1=/tmp/{$TimE}.mailjoin1.tmp 
  190. set tempcatFile=/tmp/{$TimE}.mailjoin.cat.tmp 
  191. set tempuncompressFile=/tmp/{$TimE}.mailjoin.uncompress.tmp 
  192. set nawkFile=/tmp/{$TimE}.mailjoin.nawk.tmp 
  193. set haveObject=0
  194. onintr interrupted
  195.  
  196. echo " ** mailjoin version $REV  **"
  197. #
  198. ### command line
  199. #
  200. foreach String ($argv)
  201.     if ( "$String" == "-help" || "$String" == "-h" ) then
  202.         echo "Purpose:"
  203.         echo "  provide a standard means of recovering mailsplit objects"
  204.         echo ""
  205.         echo "Usage:"
  206.         echo "  mailjoin [object]"
  207.         echo ""
  208.         echo "Note:"
  209.         echo "  An objects name is given on the subject line of the mail message"
  210.         echo "  e.g."
  211.         echo "     subj:  everest.gif - part 1 of 14"
  212.         echo "  Here the object is everest.gif"
  213.         echo ""
  214.         exit(0)
  215.     else if ( ! $haveObject ) then
  216.             set object=$String
  217.             set haveObject=1
  218.             echo " "
  219.             echo "Choose object $object on command line"
  220.     else
  221.             echo "WARNING *** unrecognized option '$String' on command line." 
  222.     endif
  223. end
  224.  
  225. while ( ! $haveObject )
  226.     echo -n "Object: "
  227.     set object=$<
  228.     if ( "$object" !~ "" ) then
  229.         set haveObject=1
  230.     endif
  231. end 
  232.  
  233. echo " "
  234. if ( -d $MAILS ) then
  235.     echo "Using Mentor mail recovery routine."
  236.     set mailFile=$tempFile1
  237.     echo "Gathering all $MAILS/m*.msg files ..."
  238.     set saveDir=`pwd`
  239.     cd $MAILS         # go to mail directory.
  240.     cat `ls -1 m*.msg | sed 's|[msg.]||g' | sort -nr | nawk '{printf("m%s.msg ",$1)}'` > $mailFile 
  241.     chdir $saveDir
  242. else
  243.     echo "Using UNIX mail recovery routine."
  244.     set mailFile=$MAILS
  245.     echo "Using $mailFile file ..."
  246. endif
  247.  
  248. cat > $nawkFile <<!
  249. BEGIN {
  250.     error = 0
  251.     first = 1
  252.     printLine = 0
  253.     process = 1
  254. }
  255. {
  256.     if (process) {
  257.         if (\$0 ~ /^--- start of .* part ([0-9]*) of ([0-9]*)\$/) {
  258.             if (\$4 == object) {
  259.                 if (first) {
  260.                     first = 0
  261.                     totalNum = \$NF
  262.                     for (i=1; i<=totalNum; i++) found[i] = 0
  263.                 }
  264.                 else {
  265.                     process = 0
  266.                     for (i=1; i<=totalNum; i++) if (found[i] == 0) process = 1
  267.                 }
  268.                 thisOne = \$6
  269.                 found[thisOne] = 1
  270.                 printLine = 1
  271.                 tempFile = sprintf("%s%d", temp, thisOne)
  272.             }
  273.         }
  274.         else if ( NF == 0 ) printLine = 0
  275.         else if (( NF == 1 ) && (length(\$1) == 1) && ( \$1 ~ /\`/ )) printLine = 0
  276.         else if (\$0 ~ /^--- end of .* part ([0-9]*) of ([0-9]*)\$/) printLine = 0
  277.         else if ((thisOne == totalNum) && (\$0 ~ /^end\$/)) printLine = 0
  278.         else if (printLine) print \$0 >> tempFile
  279.     }
  280. }
  281. END {
  282.     for (i=1; i<=totalNum; i++) {
  283.         if ( ! found[i]) {
  284.             print "ERROR *** part " i " of " totalNum " not found."
  285.             error = 1
  286.         }
  287.     }
  288.     if (error) exit 1
  289.     tempFile = sprintf("%s%d", temp, totalNum)
  290.     printf("\`\nend\n") >> tempFile
  291.     for (i=1; i<=totalNum; i++) command = sprintf("cat %s%d", temp, i)
  292.     system(command " > " catfile)
  293.     print "... found all " totalNum " pieces of " object " ..."
  294. }
  295. !
  296.  
  297. echo ""
  298. echo "... extracting pieces of $object object ..."
  299. nawk -f $nawkFile $V object=$object $V temp=$tempFile1 $V catfile=$tempcatFile  $mailFile 
  300. if ($status) then
  301.     echo "Problems .... aborting."
  302.     goto errorExit
  303. endif
  304. rm -f ${tempFile1}* $nawkFile
  305.  
  306. echo ""
  307. echo "... finished extraction, starting uudecode ..."
  308. set tempuncompressFile=`head -100 $tempcatFile | grep begin | sed 's/.* .* //'`
  309. set saveDir=`pwd`
  310. chdir /tmp
  311. touch $tempcatFile
  312. chmod -f 777 $tempcatFile
  313. uudecode $tempcatFile
  314. if ($status) then
  315.     echo "Problems .... aborting."
  316.     goto errorExit
  317. endif
  318. rm -f $tempcatFile
  319. chmod 777 $tempuncompressFile
  320. mv $tempuncompressFile ${tempuncompressFile}.Z
  321.  
  322. echo ""
  323. echo "... finished uudecode, starting uncompress ..."
  324. uncompress `basename ${tempuncompressFile}.Z`
  325. mv $tempuncompressFile $saveDir
  326. chdir $saveDir
  327.  
  328. echo ""
  329. echo "... finished uncompress, starting tar extraction ..."
  330. tar -xvf `basename $tempuncompressFile`
  331.  
  332. exit(0)
  333. interrupted:
  334. echo "**** interrupted ****"
  335. errorExit:
  336. /bin/rm -f ${tempFile1}* $tempcatFile $nawkFile $tempuncompressFile
  337. exit(1)
  338. #----------------- end cut here for mailjoin routine ---------------------------
  339. MAILJOIN!END
  340.  
  341. case $RA in               # hacked from usenet commentary; will
  342.   all) ;;                 # be replaced by an awk script RSN
  343.   *  )
  344.     SIFS="$IFS"
  345.     IFS=","
  346.     for i in $RA ; do
  347.       R=$R" "$i
  348.     done
  349.     RA=$R
  350.     IFS=$SIFS
  351.     R=""
  352.     for tok in $RA ; do
  353.       case $tok in 
  354.       *-*)
  355.         SIFS="$IFS"
  356.         IFS='-'
  357.         set $tok
  358.         IFS="$SIFS"
  359.         i=$1
  360.         max=${2:-99}
  361.         while $TEST $i -le $max ; do
  362.           R=$R" "$i
  363.           i=`expr $i + 1`    # only exec in the entire parse
  364.         done ;;
  365.       *) R=$R" "$tok ;;
  366.       esac
  367.       RA=$R
  368.     done ;;
  369. esac
  370.  
  371. case $DB in
  372.   5|6|7|8|9) echo "...beginning tar and compress..." ;;
  373. esac
  374. set $FL ; shift
  375. for i in $* ; do
  376.   if $TEST -s $i ; then       # Test existence of each file to send
  377.     FC=`expr $FC + 1`         # Increment file counter
  378.   fi
  379. done
  380. if $TEST $FC -gt 0 ; then     # Is there something to send?
  381.   case $DB in                 # Yup. continue
  382.     1|2|3|4) 
  383.       case $TM in
  384.         true )
  385.           echo "would have issued command:"
  386.           echo "$TA cvf - $* 2> /dev/null | $CO $CF >$T1" ;;
  387.         false)  $TA cvf - $* 2> /dev/null | $CO $CF  >$T1 ;;
  388.         *    ) echo "Sigh... Programmer error in $ME at line 93." ;;
  389.       esac ;;
  390.     *) 
  391.       case $TM in
  392.        true )
  393.          echo "would have issued command:"
  394.          echo "$TA cvf - $* | $CO $CF >$T1" ;;
  395.        false) $TA cvf - $* | $CO $CF >$T1 ;;
  396.        *    ) echo "Sigh... Programmer error in $ME at line 153." ;;
  397.       esac ;;
  398.   esac
  399. else                          # Nope, nothing to send
  400.   case $DB in
  401.     [5-9] ) echo "...whoops!  Nothing to send!  Punting..." 1>&2 ;;
  402.   esac
  403.   exit 1
  404. fi
  405. case $DB in
  406.   5|6|7|8|9) echo "...finished tar, compress, starting uuencode..."
  407. esac
  408. case $TM in
  409.   true )
  410.     echo "would have issued command:"
  411.     echo "$UU $T1 $T1 > $T2 " ;;
  412.   false) $UU $T1 $T1 > $T2 ; ;;
  413.   *    ) echo "Sigh... Programmer error in $ME at line 170." ;;
  414. esac
  415. case $DB in
  416.   5|6|7|8|9) echo "...finished uuencode, starting split..." ;;
  417. esac
  418. case $TM in 
  419.   true )
  420.     echo "would have issued command:" 
  421.     echo "$SPLIT -$LI $T2 $T3" ;; 
  422.   false)  $SPLIT -$LI $T2 $T3 ; ;; 
  423.   *    ) echo "Sigh... Programmer error in $ME at line 128." ;;
  424. esac 
  425. case $TM in
  426.   true )
  427.     echo "would have issued commands:"
  428.     echo "$MA -s "$SU - part n of m" $TO" 
  429.     echo "with n ranging from 1 to m; m cannot be determined."
  430.     echo "without running for real."
  431.     exit 0 ;;
  432. esac 
  433.  
  434. n=1
  435. set $T3*
  436. for f  do
  437.   SE=false
  438.   case $RA in
  439.     all)  SE=true ;;
  440.     *  )
  441.       for p in $RA ; do
  442.         case $p in
  443.           $n ) SE=true ;;
  444.         esac
  445.       done ;;
  446.   esac
  447.   case $SE in
  448.     true)
  449.     {
  450.     echo " "
  451.     case $n in
  452.     1)
  453.       if $TEST ! -s $f ; then
  454.         case $DB in 
  455.           [5-9]) echo "...whoops!  $SPLIT failed!   Punting..." 1>&2 ;;
  456.         esac 
  457.         exit 1 ;
  458.       fi
  459.       case $IJ in
  460.         true) cat $T4 ;;
  461.       esac
  462.       echo " " ;;
  463.     esac
  464.     echo " "
  465.     echo "This file was packed by mailsplit version:"
  466.     echo $VE
  467.     echo with command:
  468.     echo "$CM"
  469.     echo "on: `date`"
  470.     echo " "
  471.     echo "--- start of $SU part $n of $#"
  472.     $CAT $f
  473.     echo "--- end of $SU part $n of $#"
  474.     echo " "
  475.     echo " "
  476.     } | 
  477.     case $MS in
  478.       Subj)  $MA $MF -s "$SU - part $n of $#" $TO ;;
  479.       *)     $MA $MF $TO ;;
  480.     esac
  481.     case $DB in
  482.       [5-9])   echo "...sent part $n of $# to $MA..." ;;
  483.     esac
  484.     case $DB in
  485.       5|6|7|8|9) echo "...sleeping $DE seconds (waiting for mailer) ..." ;;
  486.     esac
  487.     $SLEEP $DE ;;
  488.   esac
  489.   n=`expr $n + 1`
  490. done
  491. $RM -f $T1 $T2 $T3* $T4
  492.