Solved

Ask question requiring user input of Y/N

Posted on 2006-10-30
6
1,173 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 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
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.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
Internet Connection Util 8 114
Date variable in batch file 2 82
How to split number value into 5 and store them in a variable in DOS batch file 7 73
Renaming with batch file 9 108
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

752 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