Batch script to monitor a service and automatically start the service if stopped. Need the output of to a logfile

Batch script to monitor a service and automatically start the service if stopped. Need to write the output of the net start command into a logfile. Executed the below script but failed to get the output into the log

net start | find /i "bits"
if "%errorlevel%"=="1" ( echo Service "Print Spooler" starting at %time% on %date% by Script 
%0>>C:\Users\DivyaBhargavMuddu\Desktop\ServiceRestart.Log
sc config "spooler" start=auto
FOR /F "tokens=*" %%F IN ('net start spooler ') DO ( Set var=%%F)
Set /P var =< "C:\Users\DivyaBhargavMuddu\Desktop\ServiceRestart.Log"
)


from Recent Questions - Stack Overflow https://ift.tt/3Gta3qO
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations