Solved

Ask question requiring user input of Y/N

Posted on 2006-10-30
6
1,168 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
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
GuruGary earned 500 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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