#
# A simple TCL scheduler script to run the first job found if the
# load average is less than or equal to 2.
#
# Author: Tom Proett, CSC-NAS, NASA Ames Research Center
# 
# connect to resource monitor and get load average
set host_con [openrm localhost]
puts "got $host_con for host_con"
if {$host_con < 0} {
        puts "bad return from openrm"
        return
}
addreq $host_con "loadave"
set la [getreq $host_con]
closerm $host_con
puts "load average is $la"
#
if {$la > 2.0} {
	puts "system load is $la which is above the PBS limit"
	return
}
#
set jobs [pbsselstat]
foreach job $jobs {
        set jid [lindex $job 0]
	pbsrunjob $jid
	return
}
