Solved

Ask question requiring user input of Y/N

Posted on 2006-10-30
6
1,157 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

18 Experts available now in Live!

Get 1:1 Help Now