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 # Latest change: Sun Jan 15 22:47:34 CET 2006 [mika]
7 ################################################################################
9 homedir="/home" # home directory for users
10 secs=10 # seconds before user is logged out
13 echo "Usage: $0 account" >&2 ; exit 1
14 elif [ "$(whoami)" != "root" ] ; then
15 echo "Error. You must be 'root' to run this command." >&2; exit 1
18 echo "Please change account $1 password to something new."
21 # Now, let's see if they're logged in, and if so, boot 'em
23 if [ ! -z $(who | grep $1) ] ; then
25 tty="$(who | grep $1 | tail -1 | awk '{print $2}')"
27 cat << "EOF" > /dev/$tty
29 *************************************************************
30 URGENT NOTICE FROM THE ADMINISTRATOR:
32 This account is being suspended at the request of management.
33 You are going to be logged out in $secs seconds. Please immediately
34 shut down any processes you have running and log out.
36 If you have any questions, please contact your supervisor or
37 John Doe, Director of Information Technology.
38 *************************************************************
41 echo "(Warned $1, now sleeping $secs seconds)"
45 killall -s HUP -u $1 # send hangup sig to their processes
46 sleep 1 # give it a second...
47 killall -s KILL -u $1 # and kill anything left
49 echo "$(date): $1 was logged in. Just logged them out."
52 # Finally, let's close off their home directory from prying eyes:
56 echo "Account $1 has been suspended."
60 ## END OF FILE #################################################################