Scripts - Passing variable info from a data file to the script

I've written a few scripts that could be much shorter if I am able to pass the contents of a data file to the script.
In short, I have a data file (servers.txt) which contains a list of my servers. One server per line.
I have a script which needs this data.  How can I pass one server name to the script at a time?

Thanks in advance..

Matthew Jones

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

billiousConnect With a Mentor Commented:

for /f %%i in (servers.txt) do call :echoname %%i
goto :eof

echo server is %1
goto :eof


It really depends on the precise format of your server ...whatevers. If they're IP addresses, then they probably contain no spaces. If they contain spaces, then change the "for" line above to

for /f "tokens=*" %%i in (servers.txt) do call :echoname %%i

which actually would work with no-spaces, too.

It's also possible to make a batch recursive

for /f "tokens=*" %%i in (servers.txt) do call %0 %%i

which will re-invoke the batch file with %1 set to each servername in turn, but probably not a requirement here.

Can be done...more details please if this isn't enough to get you going...

For more info:

for/?     from the command prompt

OR Operating Systems>MSDOS in ExpertsExchange
OR newsgroup alt.msdos.bat
OR newsgroup alt.msdos.bat.nt


matthewjonesAuthor Commented:

Thanks - You Da Man!  I just couldn't think of the format!
Very quick response too! Appreciated!
All Courses

From novice to tech pro — start learning today.