From: silvert@cs.dal.ca (Bill Silvert)
Subject: Re: Automatic FTP get?
Reply-To: silvert@biome.bio.ns.ca (Bill Silvert)
Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
Distribution: na
Date: Tue, 10 Nov 1992 20:18:26 GMT

In <1992Nov10.174729.22682@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Mr. G. Pickering) writes:

>Is there any way to get FTP to automatically drag files from a
>particular site? I have got it to auto login, but can't see how
>to "script" using it?

Here is a script that I've hacked to get the US weather map.  The
changes let it run on machines that don't support date -u (for GMT):

#!/bin/csh -f
#
# getweather - gets the latest weather GIF image file from the anonymous ftp 
# area of the server machine (SERVERHOST), in the directory (DIRNAME)
# and copies it to the file WEATHERFILE if successful
#
# this should be run hourly, on the half-hour,  in a crontab entry
#
# John Bradley, 03/26/92
#
# based on getnettables, by John Dotts Hagan

# modified by Bill Silvert to allow for delay in posting the new weather 
# map, usually about 12-14 min. past the hour.  Also contains a crude hack
# to convert the date to GMT for systems without the -u option.  This does
# not work on the last day of the month if the GMT date is in the next month.

set SERVERHOST  = vmd.cso.uiuc.edu
set DIRNAME     = wx
set ACCT        = anonymous
set PASS        = sysop@biome.bio.dfo.ca
set HOSTMANAGER = sysop
set WEATHERFILE = /usr/local/lib/weather/weather.gif
set MAILER      = /usr/sbin/Mail
set OFFSET      = 2 # one less than offset from GMT
set DELAY       = 20 # wait for new map to be posted, usually < 15 min.
set DISPLAY     = "echo Ready: "

switch ($#argv)
case 1:
        switch ($argv[1])
        case "-V":
                set DISPLAY = "xv -geometry -10+10"
                goto no_get
        case "-v":
                set DISPLAY = "xv -geometry -10+10"
                breaksw
        default:
                echo "Illegal option"
                exit 1
        endsw
endsw

set GMT = `date +%H`
set DAY = `date +%d`
@ GMT = $GMT + $OFFSET
if ( `date +%M` < $DELAY ) then
        @ GMT = $GMT - 1
endif
@ DAY = $DAY + ( $GMT / 24 )
@ GMT = $GMT % 24
if ( $DAY < 10 ) then
        set DAY = "0$DAY"
endif
if ( $GMT < 10 ) then
        set GMT = "0$GMT"
endif
set FNAME = SA`date +'%m'`${DAY}${GMT}.GIF
#set FNAME = SA`date -u +'%m%d%H'`.GIF

# echo $FNAME;exit 0 # for debugging purposes

unset noclobber
cd /usr/tmp
echo "open $SERVERHOST\
user $ACCT $PASS\
bin\
hash\
cd $DIRNAME \
dir $FNAME \
get $FNAME \
quit" | ftp -n -i -v -d

if ( ! -e $FNAME) then
#       echo "new weather file $FNAME was not created" \
#               | $MAILER -s "getweather error" "$HOSTMANAGER"
        exit(-1)
endif

if (-z $FNAME) then
#       echo "new weather file $FNAME is empty" \
#               | $MAILER -s "getweather error" "$HOSTMANAGER"
        exit(-1)
endif

cp $FNAME $WEATHERFILE.1
rm $FNAME
mv -f $WEATHERFILE.1 $WEATHERFILE
no_get:
$DISPLAY $WEATHERFILE


-- 
William Silvert, Habitat Ecology Division, Bedford Inst. of Oceanography
P. O. Box 1006, Dartmouth, Nova Scotia, CANADA B2Y 4A2.  Tel. (902)426-1577
InterNet Address: silvert@biome.bio.ns.ca
Newsgroups: alt.internet.services,ne.politics,alt.politics.elections,alt.religion.kibology,alt.politics.kibo