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