Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ask question requiring user input of Y/N

Posted on 2006-10-30
6
Medium Priority
?
1,181 Views
Last Modified: 2012-06-27
I have a script which I want to echo a question to the screen.  How do I phrase the Input from the user and take that input to either "Y" continue or "N" :END?


@ECHO OFF
ECHO
ECHO ***************************************************************
ECHO ***************************************************************
ECHO *** Danger this is a mass shutdown command and can cause massive ***
ECHO *** outages in the Data Center if used improperly or       ***
ECHO *** against the wrong server.TXT file.                      ***
ECHO *** Do you really want to run this Y or N?                  ***
ECHO ***************************************************************
ECHO ***************************************************************
ECHO

REM The output file shutdownout.txt will appear in the execution directory
REM from servers.......FOR /F %%i in (servers.txt) do shutdown /f /s /d p:4:1 /m \\%%i
REM for workstations...FOR /F %%i in (servers.txt) do shutdown /f /s /m \\%%i

IF NOT EXIST "servers.txt" goto MISSING
FOR /F %%i in (servers.txt) do (shutdown /f /s /d p:4:1 /m \\%%i
ECHO ---------- %%i sent shutdown command ----------
ECHO ---------- %%i sent shutdown command ---------- >> shutdownout.txt
)
goto END
:MISSING
ECHO The Servers.txt file is missing. Cannot continue.
:END
pause
0
Comment
Question by:johndarby
[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
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
GuruGary earned 2000 total points
ID: 17837737
I added a :Start label at the beginning of the code.  The rest of the new code is right below your ECHO commands.  Is that what you were looking for?

@ECHO OFF
:Start
ECHO
ECHO ***************************************************************
ECHO ***************************************************************
ECHO *** Danger this is a shutdown command and can cause massive ***
ECHO *** outages in the Data Center if used improperly or       ***
ECHO *** against the wrong server.TXT file.                      ***
ECHO *** Do you really want to run this Y or N?                  ***
ECHO ***************************************************************
ECHO ***************************************************************
ECHO


set /p answer=Enter Y or N:
if /i {%answer%}=={n} goto :EOF
if /i {%answer%}=={y} goto :Continue
goto :Start
:Continue


REM The output file shutdownout.txt will appear in the execution directory
REM from servers.......FOR /F %%i in (servers.txt) do shutdown /f /s /d p:4:1 /m \\%%i
REM for workstations...FOR /F %%i in (servers.txt) do shutdown /f /s /m \\%%i

IF NOT EXIST "servers.txt" goto MISSING
FOR /F %%i in (servers.txt) do (shutdown /f /s /d p:4:1 /m \\%%i
ECHO ---------- %%i sent shutdown command ----------
ECHO ---------- %%i sent shutdown command ---------- >> shutdownout.txt
)
goto END
:MISSING
ECHO The Servers.txt file is missing. Cannot continue.
:END
pause
0
 
LVL 1

Author Comment

by:johndarby
ID: 17837751
Gary, once again, you're the man! I appreciate the help. And...I now know another functional piece to shell scripting!
Thanks!
JohnD
0
 
LVL 1

Author Comment

by:johndarby
ID: 17837772
Gary, the :EOF you reference above: does it require there be an iteration of :EOF at the 'end of file' or is it assumed?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 10

Expert Comment

by:GuruGary
ID: 17837781
You're welcome!
0
 
LVL 10

Expert Comment

by:GuruGary
ID: 17837797
:EOF is built-in, so you don't need to add it to the batch file.
0
 
LVL 1

Author Comment

by:johndarby
ID: 17837802
Sweet!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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