Computing.Net > Forums > Disk Operating System > Batch file variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file variables

Reply to Message Icon

Name: Pete_Midd
Date: November 16, 2003 at 01:35:33 Pacific
OS: win2k
CPU/Ram: 266/256
Comment:

Hi.
I hve written a batch file which connects to a series of computers, checks for the existence of a file then published the result, however I have a different section in the batch file for for each PC. What I want to do is to have a serperate list of ip addresses which I can include as variables.

Here is an example of the batch file I am using. This is for 1 PC so for 20 you can imagine how unweilding it is becoming.

REM *****Room number B002*****

time /t > timeb002.txt

net use j: \\xx.xx.xx.xx\c$ password /user:administrator /y

copy smile.gif j:\temp

if not exist j:\temp\smile.gif goto badcopy1


copy timeb002.txt h:\tmp\ltcheck

goto goodcopy1

:badcopy1
copy bad.tnt h:\tmp\ltcheck\timeb002.txt

goto end

:goodcopy1


del j:\temp\*.gif


:end
net use j: /delete /y


Thanks in advance

Pete



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: November 16, 2003 at 17:11:40 Pacific
Reply:

Hi
Will something along these lines help.
Create a file with your data similar to the data below
showing room + IP address
and have the first batch file call the second batch file
with Room and IP address from each line in the IP data file.
Hope this may be of some help. I'm no expert.
Harry.

Rem IP.dat File
001 123-456-789
002 223-456-789
003 323-456-789
004 423-456-789
005 523-456-789
006 623-456-789
007 723-456-789
008 823-456-789
009 923-456-789
010 123-456-789


Rem Batch File1
echo off
for /f "tokens=1,2 delims= " %%a in (ip.dat) do call Test2.bat %%a %%b

Rem Batch File2
@echo off
REM *****Room number B002*****
time /t > timeb%1.txt
echo net use j: \\%2\c$ password /user:administrator /y
copy smile.gif j:\temp
if not exist j:\temp\smile.gif goto badcopy1
copy timeb%1.txt h:\tmp\ltcheck
goto goodcopy1
:badcopy1
copy bad.tnt h:\tmp\ltcheck\timeb%1.txt
goto end
:goodcopy1
j:\temp\*.gif
:end
net use j: /delete /y



0

Response Number 2
Name: Pete
Date: November 17, 2003 at 02:51:32 Pacific
Reply:

Thanks I'll give it a go

Pete


0

Response Number 3
Name: Pete
Date: November 17, 2003 at 03:36:52 Pacific
Reply:

Thanks very much that felt expert to me!!!!

Thanks again that really has made my life easier, I'd looked at the 'for in do' command but couldn't get my head round the tokens...

Most grateful!!

Pete


0

Response Number 4
Name: dtech10
Date: November 17, 2003 at 14:11:42 Pacific
Reply:

Hi Pete
Glad it made your life easier.

The Tokens are just like line parameters and the delims are just what seperates them, in this case a space.

the tokens passed to the second batch file are the two tokens from the data file ie Room No & IP Address these are
taken as data to the second batch file as %1=Room No and %2=IP Address for every line in the data file.
Hope this Helps.
Harry


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch file variables

Batch File Variables www.computing.net/answers/dos/batch-file-variables/7151.html

Batch File Variables Troubles www.computing.net/answers/dos/batch-file-variables-troubles/14028.html

Batch File Variables www.computing.net/answers/dos/batch-file-variables/14203.html