2 # Filename: suspenduser.sh
3 # Purpose: suspend a user account for the indefinite future
4 # Authors: Dave Taylor / http://www.intuitive.com/wicked/showscript.cgi?045-suspenduser.sh
5 # Bug-Reports: see http://grml.org/bugs/
6 ################################################################################
8 homedir="/home" # home directory for users
9 secs=10 # seconds before user is logged out
12 echo "Usage: $0 account" >&2 ; exit 1
13 elif [ "$(whoami)" != "root" ] ; then
14 echo "Error. You must be 'root' to run this command." >&2; exit 1
17 echo "Please change account $1 password to something new."
20 # Now, let's see if they're logged in, and if so, boot 'em
22 if [ ! -z $(who | grep $1) ] ; then
24 tty="$(who | grep $1 | tail -1 | awk '{print $2}')"
26 cat << "EOF" > /dev/$tty
28 *************************************************************
29 URGENT NOTICE FROM THE ADMINISTRATOR:
31 This account is being suspended at the request of management.
32 You are going to be logged out in $secs seconds. Please immediately
33 shut down any processes you have running and log out.
35 If you have any questions, please contact your supervisor or
36 John Doe, Director of Information Technology.
37 *************************************************************
40 echo "(Warned $1, now sleeping $secs seconds)"
44 killall -s HUP -u $1 # send hangup sig to their processes
45 sleep 1 # give it a second...
46 killall -s KILL -u $1 # and kill anything left
48 echo "$(date): $1 was logged in. Just logged them out."
51 # Finally, let's close off their home directory from prying eyes:
55 echo "Account $1 has been suspended."
59 ## END OF FILE #################################################################