next | next | up | down | Inhalt | Uebungen | Complete | Kommentar

all, section 8.4.

8.4.  ftp dann und das

ftp zu einer bestimmten Zeit.

 1      #!/bin/sh
 2      #       (c)                     afb     SAI Uni Ulm
 3      #       adapted                 gsk     FB6 Uni Osnabrueck
 4      #       adapted                 hpb     FB6 Uni Osnabrueck
 5      #       
 6      # Zweck: Aufruf von ftp, wobei die Kommandos, die ftp remote
 7      #        ausfuehren soll, auf der Kommandozeile mitgegeben
 8      #        werden koennen bzw. von stdin kommen.
 9      #       
10      # Optionen:-s seconds:  Bevor der ftp aufruf erfolgt,
11      #                       seconds Sekunden warten.
12      #       -f path         path wird von ls und get verwendet
13      #       -ls:            ls-Listing von path
14      #       -get:           get von path
15      #       -cat:           die Kommandos werden von stdin erwartet.
16      #       host:           ftp-Host
17      
18      PATH="/usr/local/gnu/bin:/usr/ucb:/usr/bin:/bin:/etc:/usr/etc"; export PATH
19      MYHOST=`hostname`
20      :       ${MYHOST:=jupiter}
21      echo $MYHOST | grep '\.' > /dev/null  || \
22                      MYHOST=`arp $MYHOST | sed 's/.*(\(.*\)).*/\1/'`
23      # originally "nsquery" was used to
24      # determine the full name of the
25      # requesting host, but here (OS)
26      # "nsquery" is not installed.
27      
28      
29      :       ${ANONYM:=anonymous}
30      :       ${PASSWD:=${LOGNAME:-`whoami`}@}        #${MYHOST}}
31      
32      Sleeping=0                      # sleep 0 seconds before ftp ...
33      Cmd=ls                  # default cmd
34      Cmd_line=ls             # default cmd_line
35      Ftphost=dione           # default ftp-host
36      Path=/                  # default path
37      File=                   # default filename
38      Flag_counter=0          # > 1 --> ls, get, cat exclusive !!
39      
40      #
41      # local funtions
42      #
43      fatal()
44      {
45              echo "fatal: `basename $0` [-s sec] [-ls|-get] [-f path] [-cat] host"
46              if [ $# -gt 0 ]
47              then
48                      echo "fatal:  $1"
49              fi
50              echo "        defaults: cmd     = ls"
51              echo "        defaults: seconds = 0"
52              echo "        defaults: host    = $Ftphost"
53              exit 1
54      }
55      
56      
57      # some abbreviations (for nameserver
58      # sometimes does not work correctly)
59      while [ $# -gt 0 ]
60      do
61      
62              case "$1"
63              in "")  
64              ;; -v*)         fatal           # --> usage & exit
65                              
66              ;; -ls)         Cmd=ls;         # listing only
67                              Flag_counter=`expr $Flag_counter \+ 1`
68                      
69              ;; -get)        Cmd=get;        # get file --> mode == I
70                              Flag_counter=`expr $Flag_counter \+ 1`
71                      
72              ;; -cat)        Cmd=cat;        # cat -- read from stdin
73                              Flag_counter=`expr $Flag_counter \+ 1`
74                      
75              ;; -f)          shift;
76                              Path=`dirname $1` # split file &
77                              File=`basename $1` # path
78      
79              ;; -s)          shift; Sleeping=$1
80                              if [ $Sleeping -lt 0 ]
81                              then
82                                      fatal "seconds > 0 !!!"
83                              fi
84                      
85              ;; -*)          fatal "unknown option: $1"
86              ;; *)           if [ $# -eq 1 ]
87                              then
88                                      Ftphost="$1"
89                              else
90                                      fatal "only one host."
91                              fi
92              esac
93      
94              shift
95      done
96      
97                      # only one cmd will be accepted
98      if [ $Flag_counter -gt 1 ]
99      then
10              fatal "ls, get and cat, ooohhhhhhh!!!"
10      fi
10      
10      case $Cmd
10              in cat) Cmd_line1="cat"
10                      Cmd_line2=
10              ;; *)   Cmd_line1="echo cd $Path"
10                      Cmd_line2="echo $Cmd $File"
10      esac
10      
11      
11      which ping
11      ping $Ftphost 1 1       > /dev/null
11      
11      case $?
11              in 0)   break;          # host is reachable
11              ;; *)   fatal "host is not reachable"
11      esac
11              
11      sleep $Sleeping
12      
12      {       echo open $Ftphost
12              echo user $ANONYM "\"$PASSWD\""
12              echo binary                             # ok?
12              eval $Cmd_line1
12              eval $Cmd_line2
12              echo bye
12      } | ftp -niv
12      
12      exit $?


back | next | up | down | Inhalt | Uebungen | Complete | Kommentar


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).

Last modified 03/July/97