home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / sun / misc / 5872 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  7.5 KB

  1. Xref: sparky comp.sys.sun.misc:5872 alt.sources:2793
  2. Newsgroups: comp.sys.sun.misc,alt.sources
  3. Path: sparky!uunet!usc!elroy.jpl.nasa.gov!sdd.hp.com!caen!nic.umass.edu!news.mtholyoke.edu!jbotz
  4. From: jbotz@mtholyoke.edu (Jurgen Botz)
  5. Subject: Beyond automated FTP (was: Automated FTP?)
  6. Message-ID: <BzD9Ky.MHw@mtholyoke.edu>
  7. Sender: news@mtholyoke.edu (USENET News System)
  8. Organization: Mount Holyoke College
  9. References: <1992Dec8.220145.5713@spang.Camosun.BC.CA>
  10. Date: Wed, 16 Dec 1992 19:17:20 GMT
  11. Lines: 246
  12.  
  13. In article <1992Dec8.220145.5713@spang.Camosun.BC.CA>
  14. morley@suncad.camosun.bc.ca (Mark Morley) writes:
  15.  
  16. > Does anyone have, or know of, a utility that allows FTP to run
  17. > non-interactively (ie: read it's commands from a file).  I'd like to be
  18. > able to use 'at' to queue up an FTP transfer to happen after normal work
  19. > hours.  Simply placing FTP commands in a file and redirecting the file
  20. > into the FTP program doesn't work (at least I haven't had any success so
  21. > far).
  22.  
  23. There are a number of FTP clients that can take batch commands, and
  24. even FTP client-libraries that allow you to write custom FTP programs
  25. easily, but by far the most elegant solution is to eliminate the FTP
  26. client entirely and make the global FTP space part of your file system.
  27. Then you can write ordinary shell scripts to automate "FTP" operations.
  28.  
  29. There is a program called "Alex" (from "Alexandria", as in: The
  30. Library of...)  that implements this solution as an NFS <-> FTP
  31. protocol "gateway", complete with some sophisticated caching.  You
  32. can get, build, and install it on a Unix machine that supports NFS
  33. with the script following this article.
  34.  
  35. - Jurgen Botz
  36.  
  37. ----------- snip ------------------------------------------
  38.  
  39. #!/bin/csh -f
  40. #
  41. #  This script will copy a new release of Alex into /usr/alexsrvr.
  42. #
  43. #  If there is an existing "/alex" mounted then this should
  44. #  be run as "alexsrvr", if not it should be run as "root"
  45. #  so that we can first mount alex.
  46. #
  47.  
  48. echo "args = $0 $1"
  49.  
  50. set ALEXSRVRHOME  = /usr/alexsrvr
  51. set ALEXSRVR      = alexsrvr
  52.  
  53. set Result = 0
  54.  
  55. set RELEASEDIR = /alex/edu/cmu/cs/sp/alex/src
  56.  
  57. set EFFUSER = `whoami`
  58.  
  59. if (($EFFUSER != $ALEXSRVR) && ($EFFUSER != root) && ($EFFUSER != rootl)) then
  60.     echo "This script needs to be run as either: alexsrvr, root, or rootl"
  61.     set Result = -1
  62.     goto theend
  63. else 
  64.     echo "Looks like we are running with right user id"
  65. endif
  66.  
  67. echo "Checking that /alex is mounted someplace"
  68. if (! -d /alex/edu) then
  69.   if (($EFFUSER != root) && ($EFFUSER != rootl)) then
  70.       echo "ERROR: /alex is not working and I need to be run as root to fix that"
  71.       set Result = -1
  72.       goto theend
  73.   else 
  74.       mkdir /alex
  75.       if (-f /usr/misc/.nfs/etc/mount) then
  76.           set MOUNT = /etc/misc/.nfs/etc/mount
  77.       else 
  78.           if (-f /etc/mount) then
  79.               set MOUNT = /etc/mount
  80.           else
  81.               set MOUNT = mount
  82.           endif
  83.       endif
  84.       $MOUNT -o timeo=30,retrans=300,rsize=1000,soft,intr alex.sp.cs.cmu.edu:/ /alex
  85.       if (! -d /alex/edu) then
  86.           $MOUNT -o timeo=30,retrans=300,rsize=1000,soft,intr furmint.nectar.cs.cmu.edu:/ /alex
  87.           if (! -d /alex/edu) then
  88.               echo "ERROR Could not mount alex"
  89.               set Result = -1
  90.               goto theend
  91.           endif
  92.       endif
  93.   endif
  94. endif
  95.  
  96. echo "Forcing update of directory information"
  97. cat $RELEASEDIR/.alex.update >& /dev/null
  98.  
  99. set MASTERGR = $RELEASEDIR/getalex
  100.  
  101. if (($EFFUSER == root) || ($EFFUSER == rootl)) then
  102.    echo "Now that /alex exists we are going to run as alexsrvr"
  103.    su alexsrvr $MASTERGR $1
  104.    if ($status != 0) then
  105.        echo "Seems had a problem while alexsrvr was running script"
  106.        set Result = -1
  107.        goto theend
  108.    else
  109.        echo "Finished with su"
  110.    endif
  111.    ps -aux | grep -v grep | grep alex.nanny 
  112.    if ($status != 0) then
  113.        echo "Starting Alex"
  114.        /usr/alexsrvr/bin/start.alex &
  115.        echo "Going to wait for 60 seconds"
  116.        sleep 60
  117.    else
  118.        echo "Think Alex is running"
  119.    endif
  120.    set Result = 0
  121.    goto mountalex
  122. endif
  123.  
  124. echo "Checking that this is the current version of getalex"
  125. if (-f $MASTERGR) then
  126.     diff $0 $MASTERGR > /dev/null
  127.     if (($status != 0) && ($0 != $MASTERGR)) then
  128.         echo "We have old version - use the new one"
  129.         csh $MASTERGR $1
  130.         goto mountalex
  131.     else
  132.          echo "We have a current version of getalex"
  133.     endif
  134. endif
  135.  
  136.  
  137. # special release or just the default?
  138. if (.$1. == ..) then
  139.    set ALEXRELEASE = $RELEASEDIR/alex.tar.Z
  140. else
  141.    set ALEXRELEASE = $RELEASEDIR/$1
  142. endif
  143.  
  144.  
  145. # In case we are using out own alexd we first copy the release then replace old
  146. cd $ALEXSRVRHOME
  147.  
  148. mv alexsrvr alexsrvr.`/bin/date | awk '{print $2_$3_$4}'`
  149. zcat $ALEXRELEASE | tar xvf -
  150. if ($status != 0) then
  151.     echo "Tar seems to have had trouble - we are exiting"
  152.     set Result = -1
  153.     goto theend
  154. else
  155.     echo "Finished the TAR"
  156. endif
  157.  
  158. set RELSIZE = `du alexsrvr | tail -1 | awk '{print $1}'`
  159. echo "Release size is $RELSIZE"
  160. if ($RELSIZE < 1000) then
  161.     echo "Don't believe that the alex release is this small $RELSIZE KB"
  162.     set Result = -1
  163.     goto theend
  164. endif
  165.  
  166. set OLDDIR = old.`/bin/date | awk '{print $2_$3_$4}'`
  167. mkdir $OLDDIR
  168. mv -f man src doc usr.man usr.src usr.bin usr.lib $OLDDIR 
  169. echo "Have moved the old directories off to $OLDDIR"
  170.  
  171. set N = alexsrvr
  172. mv -f $N/man $N/src $N/doc $N/usr.man $N/usr.src $N/usr.bin $N/usr.lib .
  173. echo "Have moved the new directories in"
  174.  
  175. if (! -d lib) then
  176.     echo "Looks like there is no old lib so bringing in new"
  177.     mv -f $N/lib .
  178. endif
  179.  
  180. if (! -d etc) then
  181.     echo "Looks like there is no old etc so bringing in new"
  182.     mv -f $N/etc .
  183. endif
  184.  
  185.  
  186. # see if he has done this before
  187. if (-f $OLDDIR/src/config.h) then
  188. #   He has done this before - see if his old config file is same as new
  189.     diff $OLDDIR/src/config.h src/config.h
  190.     if ($status != 0) then
  191.         echo "You need to fix src/config.h and then make installbasic"
  192.         set Result = -1
  193.         goto theend
  194.     endif
  195.     diff $OLDDIR/src/Makefile src/Makefile
  196.     if ($status != 0) then
  197.         echo "You need to fix the src/Makefile and then make installbasic"
  198.         set Result = -1
  199.         goto theend
  200.     endif
  201.     echo "Looks like you did not modify the config files in the last release"
  202. else
  203.     echo "Looks like you have not installed this before so I'll try"
  204. endif
  205.  
  206.  
  207. # Lets compile and run
  208. if ($EFFUSER == alexsrvr) then
  209.     echo "Going to run make"
  210.     if (! -d $ALEXSRVRHOME/bin) mkdir $ALEXSRVRHOME/bin
  211.  
  212.     echo "Going to run make but without rpcgen"
  213.     (cd $ALEXSRVRHOME/src; make norpcgen; make install)
  214.     if ($status == 0) goto lookinggood
  215.  
  216.     echo "Looks like make had trouble with the full release - let me just try the basics"
  217.     (cd $ALEXSRVRHOME/src; make norpcgen; make installbasic)
  218.     if ($status == 0) goto lookinggood
  219.  
  220.     echo "Seems we can not compile even the basics without your help ..."
  221.     echo "It is all in your hands now.  Good luck."
  222.     set Result = -1
  223.     goto theend
  224.  
  225. lookinggood:
  226.     echo "Think we compiled things ok"
  227.     echo "Going to kill alexd if it is running"
  228.     $ALEXSRVRHOME/bin/grepnkill alexd 
  229.     goto theend
  230. endif
  231.  
  232.  
  233. mountalex:
  234.  
  235. if (($EFFUSER == root) || ($EFFUSER == rootl)) then
  236.     ps -auxww | grep alexd >& /dev/null
  237.     if (status != 0) then
  238.         set Result = -1
  239.         goto theend
  240.     endif
  241.  
  242.     ps -auxww | grep alexmountd >& /dev/null
  243.     if (status != 0) then
  244.         set Result = -1
  245.         goto theend
  246.     endif
  247.  
  248.     echo "Going to remount Alex just to be sure we are using this server"
  249.     $ALEXSRVRHOME/bin/mountalex
  250. endif
  251.  
  252.  
  253. theend:
  254.     echo " "
  255.     echo "Your current directory is now "
  256.     pwd
  257.     exit $Result
  258.  
  259.