Solved

Ask question requiring user input of Y/N

Posted on 2006-10-30
6
1,160 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

22 Experts available now in Live!

Get 1:1 Help Now