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

Posted on 2003-04-01
Medium Priority
Last Modified: 2010-04-17
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

Question by:matthewjones
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

billious earned 500 total points
ID: 8246505

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



Author Comment

ID: 8246623

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question