Всем привет, написал скрипт, который должен выбивать активную сессию, если заходишь через RDP. Закинул вызов скрипта в /etc/xrdp/startwm.sh
:
exec /usr/bin/auto-logout-rdp-ubuntu.sh
Но скрипт не вызывает. В чем может быть проблема?
#!/bin/bash
# Set username
USERNAME_PC="continue"
# Get all sessions wo header table
sessions=$(loginctl list-sessions | awk -F ' ' 'NR>1{print $1,$2,$3,$4,$5}' | sed '/[[:digit:]] sessions listed/d' | awk 'NR>1 {print last} {last=$0}')
# Search empty tty, seat in sessions
#
#
# For example (output loginctl list-sessions with RDP user)
# SESSION UID USER SEAT TTY
# 8 1000 continue seat0 tty3
# c2 127 gdm seat0 tty1
# c3 1000 continue <----------- connect with rdp, for some reason two columns are empty, we can determine this
rdp_user_session_info=$(echo "$sessions" | awk '$4 == "" && $5 == "" && /'$USERNAME_PC'/')
rdp_user_session_id=$(echo "$rdp_user_session_info" | awk '{print $1}')
# Loop through sessions
tail <<< "$sessions" | while read -r line; do
session_id=$(echo "$line" | awk '{print $1}')
username=$(echo "$line" | awk '{print $3}')
# If iterated user == rdp user and iterated user session != rdp session, then kill
if [ "$username" == "$USERNAME_PC" ] && [ "$session_id" != "$rdp_user_session_id" ]; then
loginctl kill-session "$rdp_user_session_id"
fi
done