Results 1 to 9 of 9
Alright so I have a question about using non-interactive ftp inside a function in a bash script.
How would I use it correctly? Everytime I try to create a simple ...
- 03-02-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 4
Advice on non-interactive ftp script
Alright so I have a question about using non-interactive ftp inside a function in a bash script.
How would I use it correctly? Everytime I try to create a simple function for passing a value ( a folder name ) to a non-interactive ftp session ( it's gonna be a cron job ) and everytime I run it, it connects to the server, however does not pass any of the ftp commands along. Here's a sample of the function I'm trying to work with:
data_upload() {
DEVICE=$1
MAIN_DIR=/some/dir/$DEVICE/data
cd $MAIN_DIR
ftp -inv 192.168.1.XXX << EOF
user USER P@ssw0rD
cd $DEVICE/data
mput *.foo *.bar
close
bye
EOF
}
data_upload foobar
I want it to open the ftp session, upload to specific file types and then close the session, but be reusable several times over the course of a script. Any help or suggestions are much appreciated.
- 03-03-2008 #2
What does your screen look like after you run this script? What's the screen output?
--
Bill
Old age and treachery will overcome youth and skill.
- 03-03-2008 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
you have put on the -v flag, so show your output. you can also experiment with the -d option. Also, you can use lcd and segregate your mput command for each file type you are uploading .
Code:.... .... lcd $MAIN_DIR prompt mput *.foo mput *.bar
- 03-04-2008 #4Just Joined!
- Join Date
- Mar 2008
- Posts
- 4
On this particular setup for my ftp function, here is the output:
# ./test.sh mt2060
./test.sh: line 71: syntax error: unexpected end of file
###
I'm sure it's related to the EOF statements, but I don't think I'm using them correctly.
- 03-04-2008 #5
You say this is a non-interactive ftp script but you are at least attempting to interact with the server.
I would take a look at expect and/or autoexpect. It can "watch" your interactive session with the server and produce a script based on what it observed. You'll probably end up having to tweak the script a little bit but it can at least give you something to work from.
- 03-04-2008 #6I think you're onto something there.I'm sure it's related to the EOF statements, but I don't think I'm using them correctly.
At first I thought it might be the space you have between the << and that EOF (because I never use a space there), but it turns out that a space is perfectly fine.
But I'm guessing that your script as you posted it is not exactly the way it is as you run it. First, I don't think the script itself has everything double spaced, but I don't think that's the problem. I suspect that some of the lines in the script itself are indented. I also suspect that the final "EOF" is one of them.
Remove any spaces or tabs before that final EOF and see whether anything changes.--
Bill
Old age and treachery will overcome youth and skill.
- 03-04-2008 #7Just Joined!
- Join Date
- Mar 2008
- Posts
- 4
It'll be a couple of hours before I can go back and edit the script, but I was indenting everything inside the function brackets. I'll remove the indents to see if that resolves the issue.
- 03-05-2008 #8Just Joined!
- Join Date
- Mar 2008
- Posts
- 4
- 03-05-2008 #9Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Perhaps of some use:
Best wishes ... cheers, drlIf the redirection operator is <<-, then all leading tab characters are
stripped from input lines and the line containing delimiter. This
allows here-documents within shell scripts to be indented in a natural
fashion.
excerpt from man bashWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
