#! /opt/bin/dash
#
# os/prog/scheduler/post.sh
export PATH="/opt/bin:/bin:/usr/bin"
echo "Content-type: text/html\n\n
scheduler"
user=`echo "${REMOTE_USER}" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]'`
if [ -z "$user" ]; then echo "Bad user: ${REMOTE_USER} -> $user"; exit 1; fi
if [ -n "$HTTP_HOST" ]; then cd /os/prog/scheduler || exit 1; fi
# tomato = #FF6347
# lightgreen = #90EE90
#
in=$(cat | egrep -v '#FF6347|#90EE90')
h=$(echo "$in" | awk '{ if( $2 == "P") { print $3; exit; }}')
useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}')
q="4"; j="5"; m="15"; s="123456789"
case "$h" in
RR) p="RR";;
SJF) p="SJF";;
*) p="FIFO";;
esac
if [ -n "$useed" ]; then
seed="$useed"
msg="- seed = $seed"
else
x=$(perl -e "print unpack(\"C*\",$user);"); seed="${s}${x}"
#echo "s = $s, x = $x, seed = $seed
"
msg=""
fi
echo "$user - scheduler results $msgPolicy $p
green = correct |
red = wrong |
"
out=$(
(echo "$in"; python3 ./scheduler.py -s "$seed" -q "$q" -j "$j" -m "$m" -p "$p" -c | grep '^ \[ time') |
awk 'BEGIN { n=0; print "
Time | \
Job # | Run Time |
"; } {
# each line of user input from schedule-post looks like: U name val
# each line of input from ./scheduler.py looks like: [ time 0 ] Run job 0 for 2.00 secs
if( $1 != "") { if( $1 == "U") u[$2]=$3; else { ++n; t=$3; j=$7; r=int($9);
a=u["T"n"T"]; if( a != "" && a == t) color="#90EE90"; else color="#FF6347";
print " "a" | ";
a=u["j"n"j"]; if( a != "" && a == j) color="#90EE90"; else color="#FF6347";
print " "a" | ";
a=u["r"n"r"]; if( a != "" && a == r) color="#90EE90"; else color="#FF6347";
print " "a" |
";
}}
} END { print "
";
}'
)
if [ -z "$useed" ]; then
bad=$(echo "$out" | grep "#FF6347" | wc -l)
good=$(echo "$out" | grep "#90EE90" | wc -l)
log=$(echo "$in" | tr -dc '[:alnum:]')
echo "$(date) $user ${p}: good $good bad $bad in: $log" >> log
fi
echo "$out\n"