From: jbotz@mtholyoke.edu (Jurgen Botz)
Subject: Beyond automated FTP (was: Automated FTP?)
Organization: Mount Holyoke College
Date: Wed, 16 Dec 1992 19:17:20 GMT

In article <1992Dec8.220145.5713@spang.Camosun.BC.CA>
morley@suncad.camosun.bc.ca (Mark Morley) writes:

> Does anyone have, or know of, a utility that allows FTP to run
> non-interactively (ie: read it's commands from a file).  I'd like to be
> able to use 'at' to queue up an FTP transfer to happen after normal work
> hours.  Simply placing FTP commands in a file and redirecting the file
> into the FTP program doesn't work (at least I haven't had any success so
> far).

There are a number of FTP clients that can take batch commands, and
even FTP client-libraries that allow you to write custom FTP programs
easily, but by far the most elegant solution is to eliminate the FTP
client entirely and make the global FTP space part of your file system.
Then you can write ordinary shell scripts to automate "FTP" operations.

There is a program called "Alex" (from "Alexandria", as in: The
Library of...)  that implements this solution as an NFS <-> FTP
protocol "gateway", complete with some sophisticated caching.  You
can get, build, and install it on a Unix machine that supports NFS
with the script following this article.

- Jurgen Botz

----------- snip ------------------------------------------

#!/bin/csh -f
#
#  This script will copy a new release of Alex into /usr/alexsrvr.
#
#  If there is an existing "/alex" mounted then this should
#  be run as "alexsrvr", if not it should be run as "root"
#  so that we can first mount alex.
#

echo "args = $0 $1"

set ALEXSRVRHOME  = /usr/alexsrvr
set ALEXSRVR      = alexsrvr

set Result = 0

set RELEASEDIR = /alex/edu/cmu/cs/sp/alex/src

set EFFUSER = `whoami`

if (($EFFUSER != $ALEXSRVR) && ($EFFUSER != root) && ($EFFUSER != rootl)) then
    echo "This script needs to be run as either: alexsrvr, root, or rootl"
    set Result = -1
    goto theend
else 
    echo "Looks like we are running with right user id"
endif

echo "Checking that /alex is mounted someplace"
if (! -d /alex/edu) then
  if (($EFFUSER != root) && ($EFFUSER != rootl)) then
      echo "ERROR: /alex is not working and I need to be run as root to fix that"
      set Result = -1
      goto theend
  else 
      mkdir /alex
      if (-f /usr/misc/.nfs/etc/mount) then
          set MOUNT = /etc/misc/.nfs/etc/mount
      else 
          if (-f /etc/mount) then
              set MOUNT = /etc/mount
          else
              set MOUNT = mount
          endif
      endif
      $MOUNT -o timeo=30,retrans=300,rsize=1000,soft,intr alex.sp.cs.cmu.edu:/ /alex
      if (! -d /alex/edu) then
          $MOUNT -o timeo=30,retrans=300,rsize=1000,soft,intr furmint.nectar.cs.cmu.edu:/ /alex
          if (! -d /alex/edu) then
              echo "ERROR Could not mount alex"
              set Result = -1
              goto theend
          endif
      endif
  endif
endif

echo "Forcing update of directory information"
cat $RELEASEDIR/.alex.update >& /dev/null

set MASTERGR = $RELEASEDIR/getalex

if (($EFFUSER == root) || ($EFFUSER == rootl)) then
   echo "Now that /alex exists we are going to run as alexsrvr"
   su alexsrvr $MASTERGR $1
   if ($status != 0) then
       echo "Seems had a problem while alexsrvr was running script"
       set Result = -1
       goto theend
   else
       echo "Finished with su"
   endif
   ps -aux | grep -v grep | grep alex.nanny 
   if ($status != 0) then
       echo "Starting Alex"
       /usr/alexsrvr/bin/start.alex &
       echo "Going to wait for 60 seconds"
       sleep 60
   else
       echo "Think Alex is running"
   endif
   set Result = 0
   goto mountalex
endif

echo "Checking that this is the current version of getalex"
if (-f $MASTERGR) then
    diff $0 $MASTERGR > /dev/null
    if (($status != 0) && ($0 != $MASTERGR)) then
        echo "We have old version - use the new one"
        csh $MASTERGR $1
        goto mountalex
    else
         echo "We have a current version of getalex"
    endif
endif


# special release or just the default?
if (.$1. == ..) then
   set ALEXRELEASE = $RELEASEDIR/alex.tar.Z
else
   set ALEXRELEASE = $RELEASEDIR/$1
endif


# In case we are using out own alexd we first copy the release then replace old
cd $ALEXSRVRHOME

mv alexsrvr alexsrvr.`/bin/date | awk '{print $2_$3_$4}'`
zcat $ALEXRELEASE | tar xvf -
if ($status != 0) then
    echo "Tar seems to have had trouble - we are exiting"
    set Result = -1
    goto theend
else
    echo "Finished the TAR"
endif

set RELSIZE = `du alexsrvr | tail -1 | awk '{print $1}'`
echo "Release size is $RELSIZE"
if ($RELSIZE < 1000) then
    echo "Don't believe that the alex release is this small $RELSIZE KB"
    set Result = -1
    goto theend
endif

set OLDDIR = old.`/bin/date | awk '{print $2_$3_$4}'`
mkdir $OLDDIR
mv -f man src doc usr.man usr.src usr.bin usr.lib $OLDDIR 
echo "Have moved the old directories off to $OLDDIR"

set N = alexsrvr
mv -f $N/man $N/src $N/doc $N/usr.man $N/usr.src $N/usr.bin $N/usr.lib .
echo "Have moved the new directories in"

if (! -d lib) then
    echo "Looks like there is no old lib so bringing in new"
    mv -f $N/lib .
endif

if (! -d etc) then
    echo "Looks like there is no old etc so bringing in new"
    mv -f $N/etc .
endif


# see if he has done this before
if (-f $OLDDIR/src/config.h) then
#   He has done this before - see if his old config file is same as new
    diff $OLDDIR/src/config.h src/config.h
    if ($status != 0) then
        echo "You need to fix src/config.h and then make installbasic"
        set Result = -1
        goto theend
    endif
    diff $OLDDIR/src/Makefile src/Makefile
    if ($status != 0) then
        echo "You need to fix the src/Makefile and then make installbasic"
        set Result = -1
        goto theend
    endif
    echo "Looks like you did not modify the config files in the last release"
else
    echo "Looks like you have not installed this before so I'll try"
endif


# Lets compile and run
if ($EFFUSER == alexsrvr) then
    echo "Going to run make"
    if (! -d $ALEXSRVRHOME/bin) mkdir $ALEXSRVRHOME/bin

    echo "Going to run make but without rpcgen"
    (cd $ALEXSRVRHOME/src; make norpcgen; make install)
    if ($status == 0) goto lookinggood

    echo "Looks like make had trouble with the full release - let me just try the basics"
    (cd $ALEXSRVRHOME/src; make norpcgen; make installbasic)
    if ($status == 0) goto lookinggood

    echo "Seems we can not compile even the basics without your help ..."
    echo "It is all in your hands now.  Good luck."
    set Result = -1
    goto theend

lookinggood:
    echo "Think we compiled things ok"
    echo "Going to kill alexd if it is running"
    $ALEXSRVRHOME/bin/grepnkill alexd 
    goto theend
endif


mountalex:

if (($EFFUSER == root) || ($EFFUSER == rootl)) then
    ps -auxww | grep alexd >& /dev/null
    if (status != 0) then
        set Result = -1
        goto theend
    endif

    ps -auxww | grep alexmountd >& /dev/null
    if (status != 0) then
        set Result = -1
        goto theend
    endif

    echo "Going to remount Alex just to be sure we are using this server"
    $ALEXSRVRHOME/bin/mountalex
endif


theend:
    echo " "
    echo "Your current directory is now "
    pwd
    exit $Result

Newsgroups: comp.sys.sun.misc