jeudi 27 novembre 2014

stop / start windows service using findstr


Vote count:

0




I need to stop and start a service when certain parameters are met in a .txt file.


When my app can't connect to a database in our test environment (regular occurence) it generates the following file type in the server folder (file date changes with each occurence)


SelfTest-20141126181000-RED.txt


Within this file is the phrase


RED: Server failed to start: Unable to open database: Unable to connect to database


Every time this is generated, along with this phrase I need to stop and start a specific service.


I have never used findstr command but I think it could be useful here. Textfile needs wildcarding obviously, and i would like a results file generating with the data and time service was stopped and started. Would the following work?



findstr "RED: Server failed to start: Unable to open database: Unable to connect to database” *RED.txt
if %errorlevel%==0 (
sc stop "my service"
sc start "my service"
echo %DATE% %TIME% database >> results.txt
)


Plan is to then have this running through scheduled tasks every 30mins or so



asked 1 min ago







stop / start windows service using findstr

Aucun commentaire:

Enregistrer un commentaire