← Back to team overview

sslug-teknik team mailing list archive

Re: Shell programmering

 

On Thu, Nov 22, 2001 at 16:15:17 +0100, Emil S. Hansen wrote:


> <SNIP ftp.sh>
> #!/bin/bash
> DATADIR=/tmp/$$
> FTPCMD=$DATADIR/ftp.cmd
> LOGFILE=$DATADIR/log
> mkdir $DATADIR || exit 1
> echo "unset noclobber" > FTPCMD
> echo "user migselv mitpassword" >> FTPCMD
> echo "lcd /usr/scripts/testscripts" >> FTPCMD
> echo "cd /kataloget" >> FTPCMD
> echo "bin" >> FTPCMD
> echo "get minfil.data" >> FTPCMD
> echo "bye" >> FTPCMD
> 
> ftp -n < $FTPCMD > $LOGFILE

Der skal vel være "$" foran FTPCMD undtagen i tildeling.

Men det er dog besværligt. "cat"/bash er lettere end echo her:
(og man kan anvende variable inde i input)

#!/bin/bassh
....
....
cat << EOF > $FTPCMD
unset noclobber
user migselv mitpassword
 osv....

EOF

ftp ....

Egentlig bør det virke direkte på ftp:

ftp -n << EOF > $LOGFILE
unset noclobber
user migselv mitpassword
 osv....

EOF

Fra BASH manualen:

   Here Documents
       This type of redirection instructs the shell to read input
       from  the current source until a line containing only word
       (with no trailing blanks) is seen.  All of the lines  read
       up to that point are then used as the standard input for a
       command.


-- 
mvh Frank Damgaard  | http://home3.inet.tele.dk/frda/



References