We all know that users NEVER do what the server admin tells them. When you have a lot of users that are logged in to an LTSP server from thin client A and then they log in from thin client B, and then try to work with a browser like Firefox, they cannot. To make matters worse, if the server crashes or restarts, that user (or all users logged in) may get locked out of the LTSP environment.
After a lot of trials and errors, I found a nice little script that helps me kill every process of a specific user.
First create a file anywhere
sudo pico test.shThen paste this code:
#!/bin/bash
USER=$1
MYNAME=`basename $0`
if [ ! -n "$USER" ]
then
echo "Usage: $MYNAME username" >&2
exit 1
elif ! grep "^$USER:" /etc/passwd >/dev/null
then
echo "User $USER does not exist!" >&2
exit 2
fi
while [ `ps -U$USER | grep -v PID | wc -l` -gt 0 ]
do
PIDS=`ps -U$USER | grep -v PID | awk '{print $1}'`
echo "Killing " `echo $PIDS | wc -w` " processes for user $USER."
for PID in $PIDS
do
kill -9 $PID 2>&1 >/dev/null
done
done
echo "User $USER has 0 processes still running."
Exit and save the file. To run the file
sudo test.sh usernameReplace username with the login of the user that is locked out. Of course you need to make this file executable first.
No comments:
Post a Comment