FTP and run a loop for array problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP and run a loop for array problem
# 1  
Old 12-18-2008
FTP and run a loop for array problem

Hello,
I have a problem with my script whereby it does not want to loop.
The function of my script is to FTP into a server and go to each directory/volume in the array 'VOL'. The way the loop is suppose to work, is to go into the first volume, get the files of R(yesterday's date) and save them in another server .. 'REPOSITORY' and then move on to the other volume in the array.
The problem with my script is that it does not loop. It just runs in the first directory then ends.

Code:
if [ $# -ne 1 ]
then
        DAISAGO=1
else
        DAISAGO=$1
fi

YESTERDAY=`date -d ${DAISAGO}day+ago +%y%m%d`
REPOSITORY=/home/CDR-backups
cd $REPOSITORY

VOL=(D010AMAB D000AMAA D010AMA9 D000AMA8 D010AMA5 D000AMA6 D010AMA7 D000AMA4 D010AMA3 D000AMA2 D010AMA1 D000AMA0)

ftp -n ##.##.##.## << !EOF
user ****** ******
binary
lcd $REPOSITORY
for VOL in ${VOL[@]}
   do
    cd /$VOL
    pwd
    dir
    mget R${YESTERDAY}*
   done
bye

Below is the output after running my script.

CDR:/home # ./getama.sh
Connected to ##.##.##.##
220 Welcome to Bla Bla Bla
331 Password required.
230 User logged in, proceed
Remote system type is SOS.
200 Command okay.
Local directory now /home/CDR-backups
usage: for format
?Invalid command.
200 Directory changed.
257 Current working directory is "/D010AMAB"
500 Syntax error, command unrecognized.
227 Entering Passive Mode (##,##,##,##,11,186)
150 File status okay; about to open data connection.
DIRP_FILESEG FIXED 2048 ********
DIRP_FILESEG FIXED 2048 ********
DIRP_FILESEG FIXED 2048 ********
226 Request successful. Closing data connection.
?Invalid command.
221 Service closing control connection.


Can someone please help me.

Please and thanks.
# 2  
Old 12-18-2008
ftp is NOT a scripting language. You could create a string (script) using your loop logic from the shell and pass the resulting created script string as input to ftp.

Your version of ftp client might not like a large set of commands coming at it using the mechanism you are using though. Try it.
# 3  
Old 12-19-2008
I'm sorry, I don't quite understand. This is the first time I'm writing a shell script and I've been following some tutorials. Are you saying that I can't run a For Loop while being in an ftp session?

Also ... I'm not familiar with string (script). I tried googling it but I can't come across anything useful. Can you direct me to tutorials? I would really appreciate it.

thanks.

Last edited by tuffgong2008; 12-19-2008 at 03:44 PM.. Reason: Adding more info
# 4  
Old 12-19-2008
Yes that is what he is saying, you can only run basic FTP commands while in the FTP session.

There are plenty of articles around on passing a script as input to ftp, here is one I found on this forum:
https://www.unix.com/shell-programming-scripting/24522-loops-within-ftp-shell-session.html

Hope this helps Smilie

Last edited by ronnie_uk; 12-19-2008 at 05:22 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

2. Shell Programming and Scripting

Loop and array problem

Hi, I have the following problem that is beyond what I can currently do with bash scripting. In file 1, I have ~ 2500000 values. Note this file is not sorted. 3 19 LABEL_A 3 37 LABEL_B 2 12 LABEL_C 1 15 LABEL_D I have a list of values in "file 2" ~ 25000 unique lines: Note -... (6 Replies)
Discussion started by: hubleo
6 Replies

3. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

4. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

5. Shell Programming and Scripting

problem access array outside of loop in bash

Below is a test script I was trying to use so that I could understand why the logic was not working in a larger script. While accessing and printing array data inside the while loop, everything is fine. Outside the loop, i guess everything is null?? The for loop that is meant to cycle... (4 Replies)
Discussion started by: adlmostwanted
4 Replies

6. Shell Programming and Scripting

Array with do while and if loop

Hi All, I am trying to run a do while for an array. And in the do while, I'm trying to get a user response. Depending on the the answer, I go ahead and do something or I move on to next element in the array. So far I can read the array, but I can't get the if statement to work. Any suggestions... (5 Replies)
Discussion started by: nitin
5 Replies

7. Shell Programming and Scripting

Array and Loop Problem

I've got this problem, if I modify an array in the loop and print it, everything is fine as long as I stay in the loop. But, when I print it outside the loop, nothing happens... How can I solve this problem? Here I prepared a sample for you to see my problem; zgrw@Rain:~$ cat test asd 123... (4 Replies)
Discussion started by: zgrw
4 Replies

8. Shell Programming and Scripting

Is there a better way I could have run this loop. (For loop with two variables)

Sorry for such a dreadful title, but I'm not sure how to be more descriptive. I'm hoping some of the more gurutastic out there can take a look at a solution I came up with to a problem, and advice if there are better ways to have gone about it. To make a long story short around 20K pieces of... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

9. Shell Programming and Scripting

How to run a loop for assigning strings which are present in a file to an array

Hi Forum, I am struggling with the for loop in shell script. Let me explain what is needed in the script. I have a file which will conatin some strings like file1 place1 place2 place3 checkpoint some other text some more text Now what my requirement is the words ... (2 Replies)
Discussion started by: siri_14
2 Replies

10. Shell Programming and Scripting

Perl Array Error when run - I think???

My code isn't pretty, my verbage isn't exact and I probably don't have all my facts together (story of my life). I know what I want with this script: to join three simple lines line 1,2,3 then repeat over and over again with 4,5,6 until the end of the file. the lines are the same, date,date,text.... (3 Replies)
Discussion started by: jseager
3 Replies
Login or Register to Ask a Question