Skip to main content.
Index | Support | Documentation | FAQ

Script to Kill all users on the system

Save to a file and make executable with chmod a+x script. Note: Before using this remove all text above and including this line.

: 
# Kill all shells up so there is no chance of corruption

# Either add this to /etc/edge.start (if using edge) or
# run it from cron just before the backup is due to start.

# Who to send the mail too?
ADMINISTRATOR="root"

TODAY=`date "+%b %d"`
T1=/tmp/godown
T2=/tmp/procs

trap 'rm -f $T2 $T1 2>/dev/null;exit' 0 1 2 3 15
who -uH >$T1
Number=`cat $T1 | wc -l`
[ "$Number" -ne 1 ] && {
	cat $T1 | mail -s "Users Logged $TODAY" $ADMINISTRATOR
        }

#       Who -u sometimes lists processes that do not exist anymore
#       So we check them
ps -e | awk '{print $1}' > $T2

ishels=`sed '1d' $T1 | awk '{if (!($1 == "root" && $2 == "tty01")) print $7}'`
rishels=
for i in $ishels
do
        fgrep -x $i $T2 >/dev/null && rishels="$rishels $i"
done
[ "$rishels" ] && echo kill -9 $rishels

rm -f $T1 $T2 2>/dev/null