suse linux ftp shell script

I am working on a fairly simple shell script to ftp some files from a remote Windows 2003server to a Suse 9.2 Pro linux server.  The remote files are web log files and are stored with the date as part of the file name.  I want my shell script to ftp a copy of the file with yesterday's date.  Here is the shell script i have so far:

#!/bin/sh

yesterday=$(TZ=EST26EDT date +%d-%m-%y)
file=server_access_log.$yesterday.log


ftp -n server.ourdomain.com << "EOF"
quote user username
quote pass password
cd /tomcat/logs/
lcd /usr/local/awstats/ftp_files/
get $file
quit
EOF

echo $file
exit 0

here are the results i reveive when i try to manually run the script:

CorpDev:~/scripts # sh ftp.sh
Connected to server.ourdomain.com.
220 Microsoft FTP Service
331 Password required for username.
230 User username logged in.
250 CWD command successful.
Local directory now /usr/local/awstats/ftp_files/
local: $file remote: $file
500 'EPSV': command not understood
227 Entering Passive Mode (10,1,1,75,5,86).
550 $file: The system cannot find the file specified.
221
server_access_log.23-05-06.log


while 'echo $file' shows the proper format for my log file, my get $file command in the list of ftp commands does not translate $file to server_access_log.23-05-06.log.  What am i missing that I am unable to use the variable substitution in my script.  


Thanks in advance,

jmdowling
jmdowlingAsked:
Who is Participating?
 
mightyoneCommented:
i similar script,witch works fine on suse10.0

#!/bin/sh
USER=userid
PASSWD=userpw

yesterday=$(TZ=EST26EDT date +%d-%m-%y)
export file=server_access_log.$yesterday.log

ftp -n server.ourdomain.com > /log/ftp.worked 2> /log/ftp.failed <<SCRIPT
user $USER $PASSWD
binary
cd /tomcat/logs/
lcd /usr/local/awstats/ftp_files/
get $file
quit
SCRIPT
0
 
mightyoneCommented:
ok make sure $file is resolved before transmittet to remote host.

e.g.
get `$file`
or
get `echo $file`
0
 
jmdowlingAuthor Commented:
I gave your suggestion a try but am still unable to get this to work.  As soon as I enter the ftp -n section of my script  I loose the ability to translate the $file variable.  I also tried using double quotes instead of single and also tried the quote 'get $file' and various other combinations like that.  I also made sure I could echo the output of $file before i hit the ftp section of my script.

If anyone has any further suggestions that would be great!
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mightyoneCommented:
did you use the "special" quotes `` ?
0
 
jmdowlingAuthor Commented:
When i changed this line of my script -

ftp -n server.ourdomain.com << "EOF"

to this line -

ftp -n server.ourdomain.com << EOF

everything started working correctly for me.
0
 
mightyoneCommented:
Why B then?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.