-
Notifications
You must be signed in to change notification settings - Fork 0
/
41-suspenduser
55 lines (37 loc) · 1.51 KB
/
41-suspenduser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
## suspenduser--Suspends a user account for the indefinite future.
homedir="/home" # home directory for users
secs=10 # seconds before user is logged out
if [ -z $1 ] ; then
echo "Usage: $0 account" >&2 ; exit 1
elif [ "$(id -un)" != "root" ] ; then
echo "Error. You must be 'root' to run this command." >&2; exit 1
fi
echo "Please change account $1 password to something new."
passwd $1
# Now let's see if they're logged in and, if so, boot 'em.
if who|grep "$1" > /dev/null ; then
for tty in $(who | grep $1 | awk '{print $2}'); do
cat << "EOF" > /dev/$tty
*************************************************************
URGENT NOTICE FROM THE ADMINISTRATOR:
This account is being suspended, and you are going to be logged out
in $secs seconds. Please immediately shut down any processes you
have running and log out.
If you have any questions, please contact your supervisor or
John Doe, Director of Information Technology.
*************************************************************
EOF
done
echo "(Warned $1, now sleeping $secs seconds)"
sleep $secs
jobs=$(ps -u $1 | cut -d\ -f1)
kill -s HUP $jobs # send hangup sig to their processes
sleep 1 # give it a second...
kill -s KILL $jobs > /dev/null 2>1 # and kill anything left
echo "$1 was logged in. Just logged them out."
fi
# Finally, let's close off their home directory from prying eyes.
chmod 000 $homedir/$1
echo "Account $1 has been suspended."
exit 0