LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Need help writing a script (https://www.linuxquestions.org/questions/linux-software-2/need-help-writing-a-script-175555/)

wswartz 04-28-2004 11:42 AM

Need help writing a script
 
I need a simple script to do some testing and I'm in a bit of a hurry. Normally I'd read up on it so as to "learn to fish". But I don't think I have time for that right now so I'm hoping someone can "give me a fish"; if you know what I mean.

I'm doing some network testing and need to put some real world traffic on the network. I thought of having two pc's, one with an FTP server and another getting a file off the server. I imagine this would be a simple bash script that would do the following at the client:

1. Get a file from the FTP server.
2. When done, delete the file and go back to step 1. (and repeat forever)

That's it! Not knowing much about bash, is this something simple? Can commands be pushed into FTP tp perform such functions from bash?

Let me know if someone can help.

BS

hw-tph 04-28-2004 11:50 AM

You can use the expect command to do this, in fact scripted FTP sessions is one of the most common usages for expect.

It is *very* simple to start out with it. Either simply google a bit, or use the autoexpect script that comes with it to create a script automatically (it catches input and output and creates a script). You can then call this script from a bash script in a loop of some sort.


Håka

hw-tph 04-28-2004 12:00 PM

Oh, and another solution would be using wget. Probably even simpler:
Code:

#!/bin/bash
x=0                                                # counter
while [ $x -lt 1000 ]
do
        wget ftp://user:password@hostname/path/to/file
        rm -f file
        let "x += 1"                        # increase count
        echo "That was try number $x"
done

This would retrieve and delete the file a thousand times as fast as possible. You could add a sleep call after the echo to pause a second or so if you wish.


Håkan

wswartz 04-28-2004 03:35 PM

Thank you very much for writing the script out for me. In the spirit of learning I will check out the reference to "expect", but appreciate your assistance.

BS


All times are GMT -5. The time now is 12:38 PM.