0

I'm trying to create a bat or shell script that will let me check if my plink connection dies or becomes unresponsive and then kill the service and start it up again. It that possible?

The problem my and my buddy encountered is that we can't seem to check if the process has died on us or not and right now our solution is to use a timeout. this is a bit of a waste of time as the connection could die and stay dead for whoever knows how long or it could get killed even if it's perfectly fine.

:LOOP
START CMD /C "title connection && plink sap" > data
timeout /t 30
START CMD /C "taskkill /fi "Status eq RUNNING" /fi "WindowTitle eq connection*" /im "cmd.exe && exit"
timeout /t 5
GOTO LOOP
Dkill
  • 31
  • 5

1 Answers1

0

We found a partial solution that solves having to kill the task every time we go through the loop. It checks if the process is responding, it gets killed and this is done every 10 seconds

START CMD /C "title connectionSAPB1PLINK && plink sap"
:LOOP
timeout /t 10
taskkill /f  /fi "STATUS eq NOT RESPONDING" /fi "WindowTitle eq connectionSAPB1PLINK*"
tasklist /fi "WindowTitle eq connectionSAPB1PLINK*" /FO "csv" | find /i "cmd.exe"  > nul 2>&1
echo "%errorlevel%"
if "%errorlevel%" == "0" (GOTO LOOP) else (START CMD /C "title connectionSAPB1PLINK && plink sap" && tasklist /v  && GOTO LOOP)
Dkill
  • 31
  • 5