ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have the following script that reads a file "sort_2" that contains one column of IPs. For every loop, it tries to ftp an IP to get the a file named "vsys.tar".
I think I'm doing some error in the looping as I receive this error "syntax error: unexpected end of file".
Code:
#!/bin/bash
file=sort_2
while read -a num; do
HOST=${num}
USER=user_name
PASS=user_pass
ftp -inv $HOST << EOF
user $USER $PASS
cd test
get vsys.tar
bye
EOF
done < "$file"
exit 0
Thanks pan64 for your quick and accurate response. Further, I'm looking to save the result of every ftp session to identical file. for example, the first IP-1 to a file named IP1.ftp and so on; any idea regarding this?
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196
Rep:
increment a variable
Increment a variable as the while loop progresses:
Code:
#!/bin/bash
FILE="sort_2"
USER="user_name"
PASS="user_pass"
a=0
if [[ -s "$FILE" ]]
then
while read -a HOST
do
ftp -inv $HOST << EOF
user $USER $PASS
cd test
get vsys.tar
bye
EOF
a=$(expr $a + 1)
mv -vf vsys.tar ${HOST}${a}.ftp
done < "$FILE"
else
echo "Sorry. $FILE does not exist"
echo "Exiting ..."
exit 1
fi
Thank you all for your perfect comments. However, tonyfreeman, I think I didn't clarify my question enough so you got it on the other side. The file I'm interested to save per IP is not the transferred file itself "vsys.tar", but the ftp report while getting this file (i.e., the speed and other info while the ftp transmission is taken place).
e.g., the following info that I need to be stored in a file named "133.101.33.4.ftp"
Code:
Connected to 133.101.33.4 (133.101.33.4).
220 (vsFTPd 2.0.5)
331 Please specify the password.
230 Login successful.
250 Directory successfully changed.
local: TEST.mp3 remote: TEST.mp3
227 Entering Passive Mode (133,101,33,4,45,211).
150 Opening BINARY mode data connection for TEST.mp3 (5492819 bytes).
WARNING! 22955 bare linefeeds received in ASCII mode
File may not have transferred correctly.
226 File send OK.
5492819 bytes received in 1.21 secs (4555.78 Kbytes/sec)
221 Goodbye.
While trying the code above, I encounter another problem, which is that the ftp for some reason doesn't succeed for some IPs in the loop. How can I add another loop for only failed IPs whose stored reports (i.e., IP.ftp) don't have the speed info (i.e., in particular the WORD "Kbytes/sec")?
I look to make the failed IPs to be repeated 3 times after fishing the sotr_2, and if failure again, just go to the new 3 attempts of next failed IP.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.