Perl script for Multi Logins

Systems Administrator (jjohnston@u-r-online.com)
Mon, 26 May 1997 17:11:58 -0400

Hello I am working on modifying a perl script that I got from the archives
of this list which stops multi loggins. but there is a problem with the
script. The file killme does not contain the portmaster name as the first
record, the script then assumes that this is the first record (the port is
the first record) and tries to log onto the portmaster S0 (for example) and
kill the port username. Is there anyone out there who can help me with
this problem??????

#!/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