?
Solved

suse linux ftp shell script

Posted on 2006-05-24
6
Medium Priority
?
7,295 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:jmdowling
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:mightyone
ID: 16759979
ok make sure $file is resolved before transmittet to remote host.

e.g.
get `$file`
or
get `echo $file`
0
 

Author Comment

by:jmdowling
ID: 16763984
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
 
LVL 6

Expert Comment

by:mightyone
ID: 16770950
did you use the "special" quotes `` ?
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 6

Accepted Solution

by:
mightyone earned 450 total points
ID: 16771194
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
 

Author Comment

by:jmdowling
ID: 16777179
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
 
LVL 6

Expert Comment

by:mightyone
ID: 16779056
Why B then?
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question