Skip navigation

JSI Tip 9426. How can I disconnect idle sessions from a server than don't automatically disconnect?


If you are plagued with a file server that doesn't disconnect idle sessions, you probably experience slowing performance and/or the connection limit is exceeded.

I have scripted IdleDisconnect.bat to disconnect sessions that have been idle for two or more hours.

You can schedule IdleDisconnect.bat to run daily, or multiple times per day.

IdleDisconnect.bat contains:

@echo off
setlocal ENABLEDELAYEDEXPANSION
for /F "Tokens=1-8*" %%a in ('net session^|Find "\\"') do (
 call :sess %%a %%b %%c %%d %%e %%f %%g %%h %%i
 @echo !comp! !idle!
)
endlocal
goto :EOF
:sess
set comp=%1
set idle=00:00:00
:sessL
shift
if \{%1\}==\{\} goto sessT
set idle=%1
goto sessL
:sessT
for /f "Tokens=1 Delims=:" %%x in ('@echo %idle%') do (
 if "%%x" GTR "01" net session %comp% /DELETE
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish