Posted on 03-19-2018 01:06 PM
My problem is in my school system, children often leave their computer without logging off, so when the computer sleeps, the only person who can use the computer is that student. To combat this, we enabled fast user switching, but now we have another problem, we still only want one user at a time logged in, but we don't want the computer to be locked down to that one user, we want to be able to switch but only have one active user. Below is a script that I wrote to use with Fast User Switching, and it works, however it causes the sign-in screen to be glitchy and unusable. The accounts use LDAP.
#!/bin/bash
loggedinusers=$(who -q | sed -n 's/# users = (.*)/1/p') # Pull number of logged in users
for ((i=1; i<=loggedinusers; i++)); do
lastUser=$(last |grep "logged in" |sed -n "$i p"|awk '{print $1;}')
echo "Last User: $lastUser" #Debug
echo "Current User: $3" #Debug
if [ "$3" != "$lastUser" ]
then
echo " $lastUser was logged off" #Debug
pkill -u $lastUser loginwindow
fi
done
exit 0
Is there another way to log off all other accounts when an account logs on?