[Thinlinc-technical] How to list sessions ?

Carsten John cjohn at mpi-bremen.de
Thu Jun 2 15:56:19 CEST 2016


Hi Philippe,

I have a few command line scripts here, that may fit your needs (all quick-and-dirty hacks):

------------------------------------------------------------------------------------------------------------------------
count_connected_session.sh:

#!/bin/bash
# make sure $HOME is set as wget reads ~/.netrc for login/password
export HOME=/root/
COUNT=0
OOSERS=$(ps -efa | grep "[t]l-session: " | awk '{print $9}' | sort | uniq )
for OOSER in $OOSERS
do
    DISCONNECTED=$(wget --quiet -O - https://login.mpi-bremen.de:8080/status/sessions?details=$OOSER#anchor | grep -c "disconnected")
    if [[ $DISCONNECTED -eq 0 ]]
    then
        COUNT=$((COUNT + 1))
        echo "$OOSER  is connected"
    fi  
done
echo $COUNT 



---------------------------------------------------------------------------------------------------------------------------
count_disconnected_session.sh

#!/bin/bash
# make sure $HOME is set as wget reads ~/.netrc for login/password
export HOME=/root/
COUNT=0
OOSERS=$(ps -efa | grep "[t]l-session: " | awk '{print $9}' | sort | uniq )
for OOSER in $OOSERS
do
    DISCONNECTED=$(wget --quiet -O - https://login.mpi-bremen.de:8080/status/sessions?details=$OOSER#anchor | grep -c "disconnected")
    if [[ $DISCONNECTED -eq 1 ]]
    then
        COUNT=$((COUNT + 1))
        echo "$OOSER is disconnected"
    fi  
done
echo $COUNT 

---------------------------------------------------------------------------------------------------------------------------------------------

kill_idle_session.sh:

#!/bin/bash
# if a session is disconnected and no application is started licenses are needlessly eaten up 
# make sure $HOME is set as wget reads ~/.netrc for login/password
export HOME=/root/
OOSERS=$(ps -efa | grep "[t]l-session: " | awk '{print $9}' | sort | uniq)
for OOSER in $OOSERS
do
    # make sure user is disconnected (might just have logged in and still not started an application)
    # so far there is no easy way to get session state, but the webgui
    DISCONNECTED=$(wget --quiet -O - https://login.mpi-bremen.de:8080/status/sessions?details=$OOSER#anchor | grep -c "disconnected")
    if [[ $DISCONNECTED -eq 1 ]]
    then
        # all our wrapper script live in /usr/local/bin
        # if there are no pprocesses started from there, the session is idle
        if [[ $(ps -f -u $OOSER | grep "/usr/local/bin/") = "" ]]
        then
            TLPID=$(ps -efa | grep "[t]l-session: " | grep $OOSER |awk '{ print $2}')
            echo "$OOSER has idle session $TLPID, killing"
            kill $TLPID
        fi
    fi  
done

-------------------------------------------------------------------------------------------------------------------------------------------------------------

$HOME/.netrc :

machine YOURHOSTNAME login admin password CHANGEME


---------------------------------------------------------------------------------------------------------------------------------------------------------


cu


Carsten

 


Max Planck Institut fuer marine Mikrobiologie
- Network Administration -
Celsiustr. 1
D-28359 Bremen
Tel.: +49 421 2028568
Fax.: +49 421 2028565
PGP public key:http://www.mpi-bremen.de/Carsten_John.html 
 
-----Original message-----
> From:Philippe BOURDEU d'AGUERRE <bda at aime-toulouse.fr>
> Sent: Monday 30th May 2016 16:31
> To: Thinlinc-technical at lists.cendio.se
> Subject: [Thinlinc-technical] How to list sessions ?
> 
> I would like to get a list of sessions. Command "who" or command "ps -f 
> -C tl-session" gives Thinlinc sessions but I need more infos:
> - is session active ?
> - if session is active, IP of client
> 
> I can get these infos in Thinlinc Administration GUI but I am looking 
> for a command line tool or at least a place where I can parse these infos.
> -- 
> Philippe BOURDEU d'AGUERRE
> AIME - Campus de l'INSA			http://www.aime-toulouse.fr/
> 135 av. de Rangueil			Tél +33 561 559 885
> 31077 TOULOUSE Cedex 4 - FRANCE		Fax +33 561 559 870
> _______________________________________________
> Thinlinc-technical mailing list
> Thinlinc-technical at lists.cendio.se
> Manage your subscription:
> http://lists.cendio.se/mailman/listinfo/thinlinc-technical



More information about the Thinlinc-technical mailing list