#!/bin/bash
#use fqdn if necessary
pmlist="portmaster1"
#login names allowed to do multiple
#pipe-separated list, for egrep
exempt='name|name2'
log="/var/log/booted"
umask 077
#make sure you have these commands
if [ ! -x /usr/portmaster/pmwho -o ! -x /usr/portmaster/pmcom ]; then
echo portmaster utilities not found
exit 1
fi
# checking and cleaning up workspace
if [ ! -d /tmp/.killer ]; then
rm -r /tmp/.killer
mkdir /tmp/.killer
fi
cd /tmp/.killer
rm -f killme duplicates
# make a separate pmwho file for each portmaster; tail removes two
header lines
for each in $pmlist; do
/usr/portmaster/pmwho $each | tail +3 > $each
done
#combine all, cut down to login name, and check for duplicates. greps
remove garbage
cut -c6-16 portmaster* | grep -v '\- ' | grep -v 'PPP' | grep -Ev
"$exempt" \
| sort | uniq -d > duplicates
# get portmaster and port, put into a file.
for abuser in `cat duplicates`; do
grep " $abuser " portmaster* | tr ':' ' ' >> killme
#(running read on this, instead of making a file, didn't work. for one
thing, grep outputs
# more than one line. if it was into an array, you could read from
that.)
done
# if the killme file is not empty...
if [ -s killme ];then
#log it - start log entry
echo
---`date`----------------------------------------------------- >> $log
# parse killme file line by line & reset each port in it with
'pmcom'
# 'portmaster' 'port' 'user' are the needed variables, 'junk'
gets the rest of the line
while read portmaster port user junk; do
/usr/portmaster/pmcom -c $portmaster "reset $port"
echo "$user disconnected from $portmaster port $port " >>
$log
#echo disconnecting $user
done < killme
echo >> $log
fi