[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[K12OSN] a script for killing all users



In the past I've seen discussions on killing all users. I adapted the script killer.sh as follows and it seems to work well. I replaced the "who -u" with "ps aux" because it seems sometimes some users aren't in the who -u list. I run it at night to keep things clean.

Comments would be welcome. Also, if anyone has a script to kill idle user sessions that would be great -- that's next on my to do list.

### This defines USERS using the ps command
USERS=`ps aux | cut -f1 -d ' ' | sort -u`
### I don't want local machine accounts to be killed,
### just my Active Directory domain ones. The funny USER
### addition is to remove the first line of the ps command
NO_TOUCH_USERS=`cat /etc/passwd | cut -f1 -d ':'`\ USER

for user in $USERS; do
        echo $user
        GO=1
        for no_user in $NO_TOUCH_USERS; do
                if [ $no_user = $user ]; then
#                       echo NOT killing $user
                        GO=0
                fi
        done

        if [ $GO = 1 ]; then
#               echo killing $user
                skill -KILL -u $user
                sleep 1
                skill -KILL -u $user
        fi
done


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]