Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    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.

  3. #3
    Linux 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

  4. #4
    Just 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.

  5. #5
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    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.

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I'm sure it's related to the EOF statements, but I don't think I'm using them correctly.
    I think you're onto something there.

    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.

  7. #7
    Just 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.

  8. #8
    Just Joined!
    Join Date
    Mar 2008
    Posts
    4
    Quote Originally Posted by wje_lf View Post
    I think you're onto something there.

    Remove any spaces or tabs before that final EOF and see whether anything changes.
    Thanks a bunch dude!!! I removed that tab ( for strictly aesthetic purposes only ) and it looks like it works now.

  9. #9
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Perhaps of some use:
    If 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 bash
    Best wishes ... cheers, drl
    Welcome - 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 )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...