Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS Batch File Question - How to Write a Loop

Status
Not open for further replies.

marksmithy69

Programmer
Apr 20, 2001
60
CA
I am a DOS batch file newbie, so I'm not really sure how to go about getting
this done. I currently have a batch script which currently ftp's to a
remote UNIX server, and ftp's a group of files back to our local Windows
2000 server. This works fine for the one UNIX server it was designed for.
We now have a request to get the script working for 40 different servers.

The script uses 3 variables, UNIX_SERVER, DB_SID and DROPBOX. The script
ftp's to the UNIX_SERVER, cd's to DB_SID\DROPBOX and ftp's the files back to
the local server. Is it possible for me to create a feeder file containing
all 40 groups of variables, such as:

SET UNIX_SERVER=server1
SET DB_SID=sid1
SET DROPBOX=dropbox1

SET UNIX_SERVER=server2
SET DB_SID=sid2
SET DROPBOX=dropbox2

SET UNIX_SERVER=server3
SET DB_SID=sid3
SET DROPBOX=dropbox3
.
.
.
and loop through each variable set? I want to cron this to run every 10
minutes...looping through the 40 different servers and ftp'ing the files
back to the local server. I appreciate any help. Thanks a lot.
 
My batch file skills are very rusty. Sounds like you might need to use the For command (if you type for /? at command prompt, you will get lots of help. There have been a number of posts in this and the XP forum with examples of how to use it - though not necessarily exactly as you want, eg thread616-605573)
 
Use the loadcom trick:
First, copy loadfix.com as enter.com into the directory you are going to use for all of this.

In the context of that article, Data.bat would be:

enter new server1 sid1 dropbox1
enter new server2 sid2 dropbox2
enter new server3 sid3 dropbox3
.... etc.

In the context of that article, Main.bat would be:

@echo off
call data.bat

In the context of that article, New.bat would be:

SET UNIX_SERVER=%1
SET DB_SID=%2
SET DROPBOX=%3
........... your ftp processing command here.
 
Thanks for the responses. I was actually given this solution by a collegue, and it worked perfectly:

set up a text file (feeder.txt) containing


server1 sid1 dropbox1
server2 sid2 dropbox2
server3 sid3 dropbox3


then the batch line (all this on one line - no doubt you'll see it wrapped)


for /f "tokens=1,2,3" %%i in (feeder.txt) do SET UNIX_SERVER=%%i&SET
DB_SID=%%j&SET DROPBOX=%%k&call ftp_job

 
Glad you're sorted, and thanks for posting a solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top