#!/usr/local/bin/perl
#
# Terminal Load Checker - Linux RH X86 RC5DES  
#
# [Checks Load, Console, and Remote Users]
#
# Version   : 1.0.6
# Date      : 10/22/1999
#
# Copyright : (C) Chris Grahn 1999
#
# Please refer to README for Disclaimer and GNU GENERAL PUBLIC LICENSE
#
# Modify the /rc5/... path to whereever RC5 is located.  You MUST use
# absolute paths, ~/..., etc will not always work through RSH.
#
# Please note: The runtime of "-h 1" is used simply to make sure the RC5 
# client DOES NOT run longer then one hour.  This way if the cronjob to
# shutdown the client(s) does not occur, the client won't turn into a
# runaway process (which in a Lab environment is not good!).
#
# Change REMOTELOGINGATEWAY to whatever firewall/gateway users are
# required to use when logging into the Lab.
#

$maxremotelogins=3;

$load=qx/uptime | tr , ' ' | awk '{print \$10}'/;
$console=`who | grep -c :0`;
$remote=`who | grep -c REMOTELOGINGATEWAY`;
$upcount=0;
$hostn=`hostname`;
$rc5start=('/rc5/x86/rc5_x86 -h 1 -ini /rc5/x86/rc5_x86.ini -ckpoint /rc5/checkpoints/`hostname` -l /rc5/logs/`hostname`.log -quiet &');

if ($load+0 <= 1.00) 
	{print "Good on Load\n"; $upcount=$upcount+1;}
	
if ($console+0 < 1) 
	{print "Good on Console\n"; $upcount=$upcount+1;}
		
if ($remote+0 <= $maxremotelogins) 
	{print "Good on Remote Logins\n"; $upcount=$upcount+1;}

if ($upcount =="3")
        {exec($rc5start);} else {print "Failed on: "; print $hostn;}
