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
Solved

How to loop command using "for" in windows ?

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

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 69

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
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 …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

837 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