0

I am the Build Master at my company and am responsible for running our code deploys. Part of this process involves monitoring the server logs to make sure that everything succeeds and comes back online. I wrote a batch script to open up the logs automatically so I didn't have to do it manually. I have written a script where I can enter the server I want to look at and it will open up all the correct logs from that server. My problem is that I would like for the script to start back over once it opens the logs, because there are many times when I need to deploy to multiple servers at once and I would prefer to not have to re-run the script, but for some reason it always closes once it opens up the logs. I will provide some of the code I am using below.

@echo off  
:Begin  
    echo.  
    echo Select Environment (HELP to List Options)  
    set /p Environment=""  

if "%Environment%" == "HELP" (  
GOTO LIST_ENV  
) else if "%Environment%" == "Stop" (  
GOTO:EOF  
) else if "%Environment%" == "Dev02" (  
%Environment% = dgisweb02  
GOTO NON_BATCH

This section prompts me to enter a server name, or HELP, to get a list of the servers. Then it goes through if/if else statements to set the proper server name for the environment I want. I have many more environments but it wasn't necessary to list them all for the purpose of this question.

:NON_BATCH  
    %SystemRoot%\explorer.exe "\\%Environment%\gwlogs\ContactManager\logs\ablog.log"  
    %SystemRoot%\explorer.exe "\\%Environment%\gwlogs\BillingCenter\logs\bclog.log"  
    %SystemRoot%\explorer.exe "\\%Environment%\gwlogs\ClaimCenter\logs\cclog.log"  
    %SystemRoot%\explorer.exe "\\%Environment%\gwlogs\PolicyCenter\logs\pclog.log"  
    GOTO Begin

This is the NON_BATCH section that it jumps to once I would input "Dev02". The issue is that it never reaches the GOTO Begin, which should send it back up to the :Begin label at the top of the script, right? Any advice would be helpful, I don't have a lot of experience with making Batch Scripts and just made this to make my life a little easier.

EDIT So it appears that it never actually enters into this NON_BATCH section. Instead, it opens up a separate batch file that I had created a while ago to open up those logs, called Dev02.bat. I am not really sure why it's calling that file.

Compo
  • 36,585
  • 5
  • 27
  • 39
chris283
  • 3
  • 2
  • 1
    I would think that you probably wanted to use the `Start` command, which would not wait for `explorer.exe` instance to be closed again, before continuing with the next line! e.g. `Start "" "%SystemRoot%\explorer.exe" "%Environment%\gwlogs\…"` – Compo Sep 15 '20 at 20:34
  • Your code is telling it open an executable file named DEV02 if the environment is DEV02. – Squashman Sep 15 '20 at 20:48
  • 3
    What is the line `%Environment% = dgisweb02` supposed to do? Do you actually mean `set "Environment=dgisweb02"`? And there is a closing `)` missing… – aschipfl Sep 15 '20 at 22:05
  • Thanks aschipfl, that was my issue. Like I said, not real familiar with Batch Files so I didn't realize I had to use set when changes the value. – chris283 Sep 16 '20 at 14:23

1 Answers1

0

I don't know if this would help since it seems that it never reaches the last line but an easy way to restart a script is for it to call itself again and exit out once it does that. Its a workaround to see if the batch file even reaches the end of your code.

:NON_BATCH
%SystemRoot%\explorer.exe "\%Environment%\gwlogs\ContactManager\logs\ablog.log"
%SystemRoot%\explorer.exe "\%Environment%\gwlogs\BillingCenter\logs\bclog.log"
%SystemRoot%\explorer.exe "\%Environment%\gwlogs\ClaimCenter\logs\cclog.log"
%SystemRoot%\explorer.exe "\%Environment%\gwlogs\PolicyCenter\logs\pclog.log"
./thisscript.bat
exit
Toys0125
  • 16
  • 2