Regarding usage of loop in my batch code

February 12, 2011 at 07:46:21
Specs: Windows Vista
Hello friends,

This is my first post and i am here to help myself resolve queries about the following batch code:
I am using the following batch code:
set /p d=enter the day(dd)
set /p dt1=enter the month(mm)
set /p dt=enter the year(yy)
set /p yea=Also enter the century(yyyy)

cd v:\Airtel Nigeria\scr\logs

@ECHO OFF

IF "%d"=="" GOTO Exit
IF "%dt"=="" GOTO Exit
IF "%dt1"=="" GOTO Exit
IF "%yea"=="" GOTO Exit

> %0.ftp echo o 172.18.4.54
>> %0.ftp echo pmuser
>> %0.ftp echo angel@22
>> %0.ftp echo cd output
>> %0.ftp echo bin
>> %0.ftp echo prompt
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSC01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSC04__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSC05__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KDMSC02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ABMSC02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ABMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ABMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ABMSS03__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ABMSS04__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ASMSC01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ASMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ASMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_BAMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_BNMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_BNMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_ENMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_IBMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_IBMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_IBMSS03__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_IBMSS04__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_IBMSS05__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_IBMSS06__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KDMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KDMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KDMSS03__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KDMSS04__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KNMSC01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KNMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_KNMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS03__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS04__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS05__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS06__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS07__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS08__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSS09__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSC02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSC03__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSC06__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LGTSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_PHMSC02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_PHMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_PHMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_PHMSS03__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_UYMSS01__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_UYMSS02__%d%dt1%dt%.txt"
>> %0.ftp echo mget mget "ZAIN_SCR_LAMSC12__%d%dt1%dt%.txt"
>> %0.ftp echo bye
ftp -s:%0.ftp

Here i want to use a for loop something like "for node = 1 to 50" taking nodes from the notepad "nodelist.txt" containg following 50 nodes:
LGTSC01
LGTSC04
LGTSC05
KDMSC02
ABMSC02
ABMSS01
ABMSS02
ABMSS03
ABMSS04
ASMSC01
ASMSS01
ASMSS02
BAMSS01
BNMSS01
BNMSS02
ENMSS01
IBMSS01
IBMSS02
IBMSS03
IBMSS04
IBMSS05
IBMSS06
KDMSS01
KDMSS02
KDMSS03
KDMSS04
KNMSC01
KNMSS01
KNMSS02
LAMSS01
LAMSS02
LAMSS03
LAMSS04
LAMSS05
LAMSS06
LAMSS07
LAMSS08
LAMSS09
LGTSC02
LGTSC03
LGTSC06
LGTSS01
LGTSS02
PHMSC02
PHMSS01
PHMSS02
PHMSS03
UYMSS01
UYMSS02
LAMSC12
so it will shorten my code to somthing like below:
set /p d=enter the day(dd)
set /p dt1=enter the month(mm)
set /p dt=enter the year(yy)
set /p yea=Also enter the century(yyyy)

cd v:\Airtel Nigeria\scr\logs

@ECHO OFF

IF "%d"=="" GOTO Exit
IF "%dt"=="" GOTO Exit
IF "%dt1"=="" GOTO Exit
IF "%yea"=="" GOTO Exit

> %0.ftp echo o 172.18.4.54
>> %0.ftp echo pmuser
>> %0.ftp echo angel@22
>> %0.ftp echo cd output
>> %0.ftp echo bin
>> %0.ftp echo prompt
>> %0.ftp echo mget mget "ZAIN_SCR_"%node%"__%d%dt1%dt%.txt"
>> %0.ftp echo bye
ftp -s:%0.ftp

Please help me in the implementation of the for loop.
Thanks in advance.


See More: Regarding usage of loop in my batch code

Report •

#1
February 12, 2011 at 20:55:23
Hi friends ,

I really need this help!!!!!!!


Report •

#2
February 13, 2011 at 13:37:44
i do know why you are using %0.ftp. better if you use some other text file as script.
have a look to http://www.computing.net/howtos/sho... it will give you some ideas on using ftp scripts.

for the loop can you try this..

@ECHO OFF
IF "%d"=="" GOTO Exit
IF "%dt"=="" GOTO Exit
IF "%dt1"=="" GOTO Exit
IF "%yea"=="" GOTO Exit
> %0.ftp echo o 172.18.4.54
>> %0.ftp echo pmuser
>> %0.ftp echo angel@22
>> %0.ftp echo cd output
>> %0.ftp echo bin
>> %0.ftp echo prompt
for /f "tokens=*" in (nodes.txt) do echo (
echo mget mget "ZAIN_SCR_"%node%"__%d%dt1%dt%.txt" >>%0.ftp
>> %0.ftp echo bye
ftp -s:%0.ftp

Subhash Chandra.
www.s-chandra.co.cc


Report •

#3
February 13, 2011 at 20:46:15
HI Subhash,

As told by you I am now using the following code:
> %0.ftp echo o 10.199.5.83
>> %0.ftp echo pmuser
>> %0.ftp echo angel@22
>> %0.ftp echo cd output
>> %0.ftp echo bin
>> %0.ftp echo prompt
for /f "tokens=*" IN (nodelist.txt) do echo (
echo mget mget "ZAIN_SCR_"%tokens%"__%d%%dt1%%dt%.txt" >>%0.ftp
>> %0.ftp echo bye
ftp -s:%0.ftp

but now I am getting following error while executing the script:
"IN was unexpected at this time."

Kindly help again!!!


Report •

Related Solutions

#4
February 13, 2011 at 23:58:55
try this..i cant test it on my system so may be another error but i know it will work in few attempts


> %0.ftp echo o 10.199.5.83
>> %0.ftp echo pmuser
>> %0.ftp echo angel@22
>> %0.ftp echo cd output
>> %0.ftp echo bin
>> %0.ftp echo prompt
for /f "tokens=*" %%a IN (nodelist.txt) do echo (
echo mget mget "ZAIN_SCR_"%%a"__%d%%dt1%%dt%.txt" >>%0.ftp
>> %0.ftp echo bye
ftp -s:%0.ftp

Subhash Chandra.
www.s-chandra.co.cc


Report •

Ask Question