This post is about how to programatically log off the sessions that becomes Inactive.
The question came from a friend of mine and I did let him know that some of those sessions that you see in EAS which is not attached to an Application are all not inactive.
In the screenshot the Sessions for Huron is an active session (that’s me), that user is an admin who might have executed a MaxL which is server specific.
However I thought it is fun to do this purely from a fun perspective and created a batch file for it.
You can download it from here.
What I’m doing in that script is first to get all sessions using display session all MaxL and spool that to a file.
There is a second MaxL which gives me all the applications that are there in the system display application all
Once I got the spool files I’m using for loop to get the required information.
REM This grabs the App Name and the Session ID from MaxL spool file (2nd and 4th column of spool file) FOR /F "usebackq tokens=1,2,3,4,* skip=4" %%a IN ("%BASE_DIR%Logssessions.log") DO echo %%b %%d>> %BASE_DIR%LogsApp_Session.txt
What the script is doing is get the 2nd and 4th token, also I asked it to skip 4 lines, this is my header.
Here is the output of the above command
0 0 is the session you’ve logged in through MaxL (the one which triggered the display session command)
– – is the byproduct of our for loop (this line is producing that OK/INFO – 1241044 – Records returned: [27].)
Now to get the Cubes, I guess you get the idea now.
REM This grabs all App names from the spool file FOR /F "usebackq tokens=1 skip=4" %%a IN ("%BASE_DIR%Logsapplications.log") DO echo %%a>> %BASE_DIR%LogsCubes.txt
Again a for loop and get the first token
Now comes the comparison where I’ve to pass column 2 from App_Session.txt to Cubes.txt and get the ones which does match.
REM Awk command compares the App Names from the Sessions with all application names and will provide with the ones that are not matching, which are our null sessions REM For loop is going to print the session id that is not associated with an application into MaxL creation FOR /F "usebackq tokens=1 eol=-" %%a IN (`%BASE_DIR%Exesgawk.exe "NR==FNR{IGNORECASE=1; c[$1]++;next};c[$2] == 0 {print $1}" %BASE_DIR%LogsCubes.txt %BASE_DIR%LogsApp_Session.txt`) do if %%a NEQ 0 (echo alter system logout session %%a; >> %MAXL_DIR%Kill_SessionID.msh)
This is achieved using gawk and for loop
gawk compares and gives us the sessionid which is not associated with an application and in this case we’ll get 0 0 – – and the reals ones.
Bring for loop to the picture and say eol=- this will remove – – and add an if condition which check whether the session id is not equal to 0 and add the ones which are not to the MaxL.
Here is the MaxL that is been created and the spool output.
One issue that I found while playing with this was you cannot use an encrypted MaxL for this.
You cannot use encrypted MaxL with display command.