home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 42 < prev    next >
Encoding:
Internet Message Format  |  1990-07-13  |  5.6 KB

  1. From: joe@auspyr.UUCP (Joe Angelo)
  2. Newsgroups: comp.sources.misc
  3. Subject: Recursive(dir) UUCP queuer script; someone might need it someday
  4. Message-ID: <2846@ncoast.UUCP>
  5. Date: 11 Jul 87 02:07:56 GMT
  6. Sender: allbery@ncoast.UUCP
  7. Organization: Austec, Inc., San Jose, CA. USA
  8. Lines: 215
  9. Approved: allbery@ncoast.UUCP
  10. Xref: ncoast comp.sources.misc:130 alt.sources:3
  11. X-Archive: comp.sources.misc/8707/42
  12.  
  13. [[ sent to alt.sources, comp.sources.unix ]]
  14.  
  15. This is the sort of thing we aren't likely to see (anymore) in a moderated
  16. news group... [[ no, I'm not trying to start anything!! ]]
  17.  
  18. -------------------------------------------------------------------------
  19.  
  20. echo >/dev/null '
  21.  
  22. I have seen lots of requests for a recursive UUCP script; most of which
  23. generate a "uucp" command line at the end of a "find"; ei: find -exec uucp.
  24. Yukky and boring. Well, my method is not much better. 
  25.  
  26. The attached script will generate a C. file for the remote system
  27. and place it in the UUCP queque dirs (if permissions provide, otherwise,
  28. the file is saved elsewhere; like /tmp). The script works for V7, BSD,
  29. and HoneyDanber UUCP since the format of C. files is exactly the same;
  30. even the name is VERY similar.
  31.  
  32. The only problem might be that some systems use a 5 character instead of
  33. a 6 character UUCP ID string in the name of the C. file; it is easy to
  34. fix if you have one of these systems -- look for the sick sed line.
  35.  
  36. There are some problems expanding .. and ../../../../.., but what the
  37. heck -- this script was mostly designed for internal xfer of large
  38. directories of source code and was found to be quite useful.
  39.  
  40. Any/all suggestions/warnings/impeachments welcome...
  41.  
  42. --
  43. "Need input.    Joe Angelo, Sr. Sys. Engineer @ Austec, Inc., San Jose, CA.
  44.  More input.    ARPA: auspyr!joe@lll-tis[-b].arpa     PHONE: [408] 279-5533
  45.  Ahhh, input!"  UUCP: {sdencore,cbosgd,ptsfa,dana}!aussjo!joe
  46.                 UUCP: {amdahl,lll-tis,imagen,necntc,dlb,sci,altnet}!auspyr!joe
  47. '
  48.  
  49. # uuqr -- takes file name list from stdin or args (via find) and generates
  50. # a C. file for uucp in the name of the remote system.
  51. #
  52. # usage:
  53. #
  54. # uuqr [dirs] system!directory
  55. #
  56. # examples:
  57. #
  58. # uuqr /tmp anysystem!        xfer all in /tmp to anysystem!~nuucp/tmp/
  59. # uuqr /tmp anysystem!/foo    xfer all in /tmp to anysystem!/foo/tmp
  60. # uuqr /tmp anysystem!/        xfer all in /tmp to anysystem!/tmp
  61. # uuqr . anysystem!/duplicate    xfer all in . to anysystem!/duplicate
  62. #
  63. # uuqr anysystem        xfer all f-names from stdin to anysystem!~nuucp
  64. # uuqr anysystem!/tmp        xfer all f-namme from stdin to anysystem!/tmp
  65.  
  66. case $# in
  67. 0)
  68. echo Usage: $0 '[dirs] system!directory
  69.  
  70. Where: dirs is a find(1) dir_name or nothing to denote
  71. that file name list comes from standard input'
  72.     exit
  73.     ;;
  74. esac
  75.  
  76. #
  77. # UUCP queue organization
  78. #
  79. # Set TYPE to:    If:
  80. # LINEAR    /usr/spool/uucp contains FILES in form of C.*, D.*, X.*.
  81. # SUBDIRS    /usr/spool/uucp contains DIRS in form of C. D. X., D.hostname.
  82. # HONEYBABY    /usr/spool/uucp contains DIRS for each remote host.
  83.  
  84. TYPE=HONEYBABY
  85. TYPE=LINEAR
  86. TYPE=SUBDIRS
  87.  
  88. PWD=`pwd`
  89. DIR=/usr/spool/uucppublic
  90.  
  91. #
  92. # USER=$LOGNAME if SYSV
  93. #
  94. USER=$USER
  95. for arg in $*
  96. do
  97.     case "$arg" in
  98.         *!*) 
  99.             HOST=`echo "$arg" | cut -d! -f1`
  100.             XDIR=`echo "$arg" | cut -d! -f2`
  101.             DIR=`echo $XDIR | awk ' {
  102.                 if( substr($1,1,1) != "/" ) 
  103.                     printf("/usr/spool/uucppublic/%s\n", $1)
  104.                 else
  105.                     printf("%s\n", $1)
  106.             }'`
  107.             ;;
  108.         *)    LIST="$LIST $arg"
  109.             ;;
  110.     esac
  111. done
  112.  
  113. #
  114. # generate the directory name to store the file into
  115. #
  116. SPOOLDIR=/usr/spool/uucp
  117.  
  118. case "$TYPE" in
  119.     HONEYBABY)    SPOOLDIR="/usr/spool/uucp/$HOST"
  120.             if test ! -d $SPOOLDIR
  121.             then
  122.                 mkdir $SPOOLDIR 1>/dev/null 2>&1
  123.             fi
  124.             ;;
  125.     LINEAR)        SPOOLDIR="/usr/spool/uucp"        ;;
  126.     SUBDIRS)    SPOOLDIR="/usr/spool/uucp/C."        ;;
  127. esac
  128.  
  129. OLDPLACE=$SPOOLDIR
  130.  
  131. #
  132. # make sure spool dir exists
  133. #
  134. DIDERROR=/bin/false
  135.  
  136. if test ! -d "$SPOOLDIR"
  137. then
  138.     echo $0: spool dir non existant, output saved elsewhere...
  139.     DIDERROR=/bin/true
  140.     SPOOLDIR=/tmp
  141. fi
  142.  
  143. # make sure we can write to the spool dir,
  144. # most portable way is to echo something into a file there; test -w nonstandard
  145. #
  146.  
  147. echo neat_stuff > /tmp/WAMMO$$ 
  148. if cp /tmp/WAMMO$$ $SPOOLDIR/WAMMO$$ 1>/dev/null 2>&1
  149. then
  150.     neat=yup
  151. else
  152.     echo $0: can not write to spooldir, output saved elsewere...
  153.     DIDERROR=/bin/true
  154.     SPOOLDIR=/tmp
  155. fi
  156.  
  157. rm -f /tmp/WAMMO$$ $SPOOLDIR/WAMMO$$
  158.  
  159. #
  160. # generate the hostname part of the C. file...
  161. # usually 6 characters only -- change for more or less.
  162. #
  163. HOSTPART=`echo $HOST | sed 's/^\(......\)\(.*\)/\1/'`
  164.  
  165. #
  166. # generate a UNIQ ID string
  167. #
  168.  
  169. STILLWORKING=/bin/true
  170. tmpid=$$
  171.  
  172. while $STILLWORKING
  173. do
  174.     # edit below if you have 6 character UUCP ids and not 5...
  175.     UUCP_ID=`echo $tmpid | sed '
  176.     s/^\([0-9][0-9][0-9][0-9]\)$/A\1/
  177.     s/^\([0-9][0-9][0-9]\)$/AA\1/
  178.     s/^\([0-9][0-9]\)$/AAA\1/
  179.     s/^\([0-9]\)$/AAAA\1/'`
  180.     CFILE=$SPOOLDIR/C.$HOSTPART$UUCP_ID
  181.     if test ! -f $CFILE
  182.     then
  183.         break
  184.     fi
  185.     tmpid=`expr $tmpid + 1`
  186. done
  187.  
  188. echo $0: saving output in $CFILE
  189.  
  190. #
  191. # is filename list from args or stdin?
  192. #
  193. (
  194. if test ! -s "$LIST"
  195. then
  196.     find $LIST -type f -print
  197. else
  198.     echo stdin
  199.     while read FILENAME
  200.     do
  201.         echo $FILENAME
  202.     done
  203. fi 
  204. ) | awk '
  205. {
  206.     # convert relative to absolute.
  207.     # keep absolute as is.
  208.     if( substr($1,1,1) != "/" ) 
  209.         name="'$PWD'/"$1
  210.     else
  211.         name=$1
  212.     printf("S %s '$DIR'/%s '$USER' -dc D.0 777\n", name, $1);
  213. }' | tr -s '/'  > $CFILE
  214.  
  215. if $DIRERROR
  216. then
  217.     echo $0: someday, you should move $CFILE to $OLDPLACE
  218. else
  219.     echo $0: $CFILE ready, now call the remote system...
  220. fi
  221. -- 
  222. "Need input.    Joe Angelo, Sr. Sys. Engineer @ Austec, Inc., San Jose, CA.
  223.  More input.    ARPA: auspyr!joe@lll-tis[-b].arpa     PHONE: [408] 279-5533
  224.  Ahhh, input!"  UUCP: {sdencore,cbosgd,ptsfa,dana}!aussjo!joe
  225.                 UUCP: {amdahl,lll-tis,imagen,necntc,dlb,sci,altnet}!auspyr!joe
  226.