#!/bin/sh

# This script takes the lab number as a command line argument
# and outpout to stdout all the folders with no submissions
# also finds the total submissions and non-submissions   
# it also records times 

lab=$1
basedir=/afs/andrew/course/15/123/handin/
baseinstrmail="guna@andrew.cmu.edu"
subj="15123S09 SL1"
message="you have not submitted Skills lab1.\nPlease respond to this message if this is an error or if you'd still like to\nsubmit the lab\n\nMessage generated by auto grader"

cat "all.txt" |
while read id
do
  userdir=$basedir$lab"/"$id/$2
  files=`ls $userdir | wc -l`
  if [ $files -eq 0 ]
   then
     countnotsubmitted=`expr $countnotsubmitted + 1`
     echo $countnotsubmitted > notsub.txt 
     echo $userdir `ls $userdir | wc -l`
     basemail=$id"@andrew.cmu.edu"
     #echo $message | mailx -s "$subj" "$basemail"
   else
     countsubmitted=`expr $countsubmitted + 1`
     echo $countsubmitted > sub.txt 
  fi
done   

cntsub=`cat sub.txt`
cntnotsub=`cat notsub.txt`

day=`date | cut -d" " -f1-4`

printf "%s " $lab >> log.txt 
printf "%s " $day >> log.txt 
printf "%s " $cntsub >> log.txt 
printf "%s \n" $cntnotsub >> log.txt


printf "The number submitted is %s \n" $cntsub
printf "number not submitted is %s \n" $cntnotsub

rm "sub.txt"
rm "notsub.txt"

#echo $message | mailx -s "$subj" "$baseinstrmail" 

#ls $basedir | wc -l   

#echo $basedir