|
Home - Old Man Programmer
| Displaying projects/sac/scripts//check
#!/bin/sh
#
# Check checks to see if any of the people who are logged in at the time
# have used up their allotment of time (as specified by MAXHOURS) on the
# modems (as specified by TTYS).
#
MAXHOURS=4.25
#TTYS="tty[C-F]*"
TTYS="tty[1-6] ttyp[0-4]"
hours=`date +%H:%M:%S`
users=`users`
u=`for x in $users; do echo $x; done | sort | uniq`
sac -pb $hours $u -T $TTYS | while read user time
do
res=`echo "$time <= $MAXHOURS" | bc`
if [ $res -eq 1 ]; then
echo "$user is OK. ($time)"
else
echo "$user is over the limit. ($time)"
fi
done
# If you use Sac to implement usage limits, the above can be modified to
# "logout" the user by modifing the above if statement to the below:
#
# if [ `expr $h '<=' $MAXHOURS` -eq 0 ]; then
# echo "You're over the time limit bozo! ($h) Bye Bye!" | write $user
# ps aux | tail +2 | while read usr PID whatever
# do
# if [ $usr = $user ]; then kill -9 $PID; fi
# done
# fi
#
# Running this script every 5-10 minutes in a cron job wouldn't be a bad idea
# either.
|