merged grml-quickconfig nonblocking branch
[grml-scripts.git] / usr_sbin / suspenduser.sh
1 #!/bin/sh
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 ################################################################################
8
9 homedir="/home"         # home directory for users
10 secs=10                 # seconds before user is logged out
11
12 if [ -z "$1" ] ; then
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
16 fi
17
18 echo "Please change account $1 password to something new."
19 passwd $1
20
21 # Now, let's see if they're logged in, and if so, boot 'em
22
23 if [ ! -z $(who | grep $1) ] ; then
24
25   tty="$(who | grep $1 | tail -1 | awk '{print $2}')"
26
27   cat << "EOF" > /dev/$tty
28
29 *************************************************************
30 URGENT NOTICE FROM THE ADMINISTRATOR:
31
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.
35
36 If you have any questions, please contact your supervisor or 
37 John Doe, Director of Information Technology.
38 *************************************************************
39 EOF
40
41   echo "(Warned $1, now sleeping $secs seconds)"
42
43   sleep $secs
44
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
48
49   echo "$(date): $1 was logged in. Just logged them out."
50 fi
51
52 # Finally, let's close off their home directory from prying eyes:
53
54 chmod 000 $homedir/$1
55
56 echo "Account $1 has been suspended."
57
58 exit 0
59
60 ## END OF FILE #################################################################