#! /opt/bin/dash # # os/prog/paging-policy/post.sh export PATH="/opt/bin:/bin:/usr/bin" echo "Content-type: text/html\n\npaging-policy" 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/paging-policy || 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; }}') #echo "
$in\n
" #exit n="15"; m="6" case "$h" in "LRU") p="LRU"; s="123456789";; *) p="FIFO"; s="123456789";; 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 - paging-policy results $msg

green = correct
    red = wrong

Policy = $p

" #echo "

"
#python3 ./paging-policy.py -s "$seed" -n "$n" -P "$P" -p "$p" -a "$a" -u "$u" -v -c
# sed -e 's/) / /' -e 's/)$//'
#echo "
" out=$( (echo "$in"; python3 ./paging-policy.py -s "$seed" -p "$p" -n "$n" -m "$m" -c | sed -e 's/FirstIn ->//' -e 's/LRU ->//' -e 's/<-.*//') | awk -v "m=$m" 'BEGIN { v=0; print ""; print ""; } { # each line of user input from paging-policy-post looks like: U name value if( $1 != "") { if( $1 == "U") u[$2]=$3; else if( $1 == "Access:") { a=$2; h=$3; print ""; x=u["h"v"h"]; if( x != "" && x == h) color="#90EE90"; else color="#FF6347"; print ""; for(i=4;i<=NF;++i) { gsub(/[^[:digit:]]/,"",$i); c["c"v"j"$i"j"]=$i; } color="#90EE90"; for(j=0;j     "; for(j=0;j"; ++v; }}}' ) 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
TimeAccessHit or MissCache (after access)
"v""a"   "x"
"