Solved

How to loop command using "for" in windows ?

Posted on 2013-12-23
5
423 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

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

707 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

13 Experts available now in Live!

Get 1:1 Help Now