Solved

How to loop command using "for" in windows ?

Posted on 2013-12-23
5
425 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
5 Comments
 
LVL 23

Assisted Solution

by:Michael74
Michael74 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 68

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 68

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

Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a trade show? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Question has a verified solution.

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

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now