3

Using who -u and w commands, we can find out which ssh sessions are idle for how many time-period. But these commands don't capture x2go sessions; x2go works over ssh though.

I am looking an equivalent of 'who u' for x2go sessions, so that idle sessions can be terminated after some specified period.

Thanks

1 Answers1

3

See x2golistsessions_root

here's a script I wrote:

LIMIT_DAYS=12

for ll in `x2golistsessions_root`; do
  #Get the date of last use of the session
  lastd=`echo $ll | awk -F \| '{print $11}' | awk -F T '{print $1}';`
  #Date in seconds
  lastsec=`date -d "$lastd" +%s`
  #Current date in seconds
  now=`date +%s`
  days=`echo $(( ($now - $lastsec) /60/60/24 ))`
  if [[ $days -gt $LIMIT_DAYS ]]; then
    sid=`echo $ll | awk -F \| '{print $2}'`
    echo "terminating session: $sid, $days days old, lastd: $lastd, lastsec: $lastsec, now: $now"
    x2goterminate-session $sid
  fi
done
michael
  • 31
  • 2