What are Ghosts Sessions?
When you lose your network connection or your FileMaker quits, sometimes your session doesn't drop off on the FileMaker server. This becomes a problem when that session hogs up one of your license spots. This doesn’t seem to happen often, but when I talked prentices to colleagues at the annual FileMaker Developer Conference, I learned it happens more often than we think.
The Process to Eliminate Ghost Sessions
So, once we identify we have a problem, we can start cooking up a solution. This particular server happens to be Windows Server. First I thought about VB scripting or Power Shell scripting. To be honest I've written one small Power Shell script, but this seemed a little above my head. So, I thought, well, here's a tool I know how to use: FileMaker. I wonder if it can do the job. It can, indeed.
The process is basically the following:
- Issue a command in Command Line to get a list of connected clients;
- Create records in a table;
- Compare them to see which ones are the same (same IP address or user);
- Issue a disconnect for everyone except for the newest connection.
So how do we do this from FileMaker? With the use of a plug-in, of course. In this case I grabbed the Base Elements plug-in, because it was already installed on the server.
The Base Elements plug-in can issue Command Line commands. I use it to get the list of connected clients:
BE_ExecuteSystemCommand ( "fmsadmin list clients -s -u <username>r -p <password>" )
The result comes back in fixed-width text format — which gave me a little headache, but I learned a lot from it. Fixed-width means that every word has a certain amount of space and the data is separated by an indeterminable number of spaces. To get that data into arrays, you have to calculate the position of the column headers.
Let ( [ text = GetValue ( $BE_output ; 1 ) ; $$pID = Position ( text ; "Client ID" ; 1 ; 1 ); $$pUname = Position ( text ; "User Name" ; 1 ; 1 ) ; $$pCname = Position ( text ; "Computer Name" ; 1 ; 1 ) ; $$pCon = Position ( text ; "Connect Time" ; 1 ; 1 ) ; $$pDur = Position ( text ; "Duration" ; 1 ; 1 ) ]; $$pID & ¶ & $$pUname & ¶ & $$pCname & ¶ & $$pCon & ¶ & $$pDur )
I then go through the result and create records from it. Now I have records to compare the timestamp on the similar records.
The way I do that is by setting up another table occurrence (user = user in my case) and then checking whether the record is a duplicate via this calculations:
TimeStamp ≠ Max ( UT__UtilityTable_User::TimeStamp )
Here is my table:
Disconnecting the Ghost Sessions
The last thing is to find the records that are marked duplicate and then loop through to issue a disconnect command for them:
# Loop through the dups and disconnect Go to Record/Request/Page [ First ] Set Variable [ $rep; Value:1 ] Set Variable [ $maxReps; Value:Get (FoundCount) ] Loop # Disconnect the client(s) Set Variable [ $ID; Value:UT__UtilityTable::ID ] Set Variable [ $command; Value:"fmsadmin disconnect client " & $ID & " -y " & " -u " & $username & " -p " & $password ] Set Variable [ $BE_output; Value:BE_ExecuteSystemCommand ( $command ) ] Set Variable [ $error; Value:BE_GetLastError ] If [ $error > 0 ] Send Mail [ Send yourself an email via SMTP so you know when there was a user disconnected.][ No dialog ] End If Exit Loop If [ $rep = $maxReps ] Go to Record/Request/Page [ Next ] End Loop
As you can see I'm using username and password variables above. Those are set in my script with the FileMaker Admin console access values I need to issue the command line commands.
Following these steps should help you eliminate ghost sessions in FileMaker and avoid overusing unnecessary license spots. Good luck! If you have any questions, let me know in a comment below or contact my team directly.