The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Assigning values to an array via for/while loop fiori_musicali Shell Programming and Scripting 2 11-24-2008 11:01 PM
Reading from while loop into an array ssuresh1999 UNIX for Dummies Questions & Answers 2 08-12-2008 11:53 AM
Array in loop is acting up RisingSun Shell Programming and Scripting 5 08-07-2008 02:21 PM
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 07:38 PM
Array Declaration and For Loop 33junaid Shell Programming and Scripting 4 09-15-2007 04:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-18-2008
tuffgong2008 tuffgong2008 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 2
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 (permalink)  
Old 12-18-2008
cjcox cjcox is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
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 (permalink)  
Old 12-19-2008
tuffgong2008 tuffgong2008 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 2
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 (permalink)  
Old 12-19-2008
ronnie_uk ronnie_uk is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 16
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:
http://www.unix.com/shell-programming-scripting/24522-loops-within-ftp-shell-session.html

Hope this helps

Last edited by ronnie_uk; 12-19-2008 at 05:22 PM..
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix commands, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0