Solved

How to loop command using "for" in windows ?

Posted on 2013-12-23
5
444 Views
Last Modified: 2013-12-24
Hi,

I have a list of domain name, eg:

abc.domain.com
domain.com
xyz.com
123.xyz.com

The file name is domainlist.txt

May i know how to run the following command and loop :

"%plesk_cli%\repair.exe" --reconfigure-web-site -web-site-name domain.com


I would like to command/script to loop change the domain.com to the domain found in the text file.

eg:

for $domain in domainlist.txt do "%plesk_cli%\repair.exe" --reconfigure-web-site -web-site-name $domain


But im not sure the correct command for the above.


Please assist.
0
Comment
Question by:smksa
[X]
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
5 Comments
 
LVL 23

Assisted Solution

by:Michael Fowler
Michael Fowler earned 100 total points
ID: 39737280
To loop through a text file line by line you can use something this


for /f "tokens=*" %%a in (input.txt) do (
  echo line=%%a
)

Michael
0
 
LVL 2

Author Comment

by:smksa
ID: 39737326
Hi Micheal,

Im not sure how to make it run :

"%plesk_cli%\repair.exe" --reconfigure-web-site -web-site-name domain.com


The "domain.com" at the end of the line is the output obtained from the input.txt

Can you help to construct the full line for me to test ?
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 400 total points
ID: 39738056
In a batch file (won't work on the command prompt that way):
@echo off
pushd %~dp0
for /F %%A in (domainlist.txt) do "%plesk_cli%\repair.exe" --reconfigure-web-site -web-site-name %%A

Open in new window

This expects the text file not to contain spaces, but I guess that is ok here ;-).
Put that into a .cmd or .bat file in the same folder as the domainlist.txt, and then run it e.g. by double-clicking in Explorer.
0
 
LVL 44

Expert Comment

by:Darr247
ID: 39738091
@Qlemo,
Wouldn't it work from the command line if you made it %A instead of %%A in both locations (and, of course, domainlist.txt instead of input.txt) ?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39738133
Darr247,

Thanks for correcting, I have changed the code snippet to use the correct file ;-).
And of course it would work in the command line, if only line 3 is used, and all %% replaced by a single %. But that is something usually confusing folks not being used to it.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

691 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