標籤:bat telnet
環境:
一台伺服器上用了portmap做了連接埠轉寄,但是這個程式經常會跪,需要人工去重啟
解決思路:
通過bat來監控程式連接埠,不通時候自動重啟,如果連接埠可用,則會出來telnet進程,若連接埠不可用,則不會出現telnet進程。根據進程是否存在來判斷連接埠是否可用,因為telnet通的話,會直接跳轉視窗,無回顯,所以需要telnet時候啟用新視窗。
方法二
@echo offtitle PortMap存活監控!!!:againset ip=127.0.0.1set port=8080start telnet.exe %ip% %port%ping -7 127.0.0.1 > nulltasklist|findstr /i "telnet.exe" > nulif ERRORLEVEL 1 (goto err) else (goto ok):errtasklist|findstr -i "portmap.exe"if ERRORLEVEL 1 (start "" "D:\PortMap1.6\PortMap.exe") else (taskkill /F -IM PortMap.exe & start "" "D:\PortMap1.6\PortMap.exe"):oktaskkill /F -IM "telnet.exe" >> nulecho PortMap Services is running %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%ping -n 300 127.0.0.1 >nulgoto again
方法二
@echo offtitle PortMap存活監控!!!:againset ip=127.0.0.1set port=8080netstat -ano|findstr %ip%:%port%|findstr -i ESTABLISHEDif ERRORLEVEL 1 (goto err) else (goto ok):errtasklist|findstr -i "portmap.exe"if ERRORLEVEL 1 (start "" "D:\PortMap1.6\PortMap.exe") else (taskkill /F -IM PortMap.exe & start "" "D:\PortMap1.6\PortMap.exe"):okecho PortMap Services is running %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%ping -n 300 127.0.0.1 >nulgoto again
本文出自 “我本不是菜鳥” 部落格,請務必保留此出處http://ityunwei2017.blog.51cto.com/7662323/1924966
Windows下bat指令碼判斷連接埠是否可用