//默认是/root/060607233目录
#!/bin/bash
stunum=$(basename $(pwd)) //返回一个字符串参数的基本文件名称
 
set $(echo $stunum|cut -c 8-9) //从文件提取考生的座号
net=$1
set $(echo $stunum|cut -c 7) //从文件提取考生的班级号
ip=$1
#echo "Student number is $net   Class number is $ip"
#echo $net   $ip
 
ifconfig | head -2 > temp  //ifconfig取得前两行
if grep "eth0" temp >& /dev/null && grep "inet addr" temp >& /dev/null
then
   set $(tail -1 temp|cut -d : -f 2)
   oldipaddr=$1
   rm -rf temp
   ifconfig eth0 192.168.$net.$ip$ip >/dev/null  //linuxip
   ping -c 2 192.168.$net.$ip >/dev/null
   if [[ $? == 0 ]]    //ping的返回值
   then
      cp /var/exam/.netrc.exam_init /root/.netrc
      ftp 192.168.$net.$ip &> /dev/null
      ifconfig eth0 $oldipaddr
   else
      printf "\tWindows XP System IP address must be 192.168.$net.$ip\n" //winip
      sleep 5
      exit 3
   fi
else
   rm -rf temp
   ifconfig eth0 192.168.$net.$ip$ip >/dev/null
   ping -c 2 192.168.$net.$ip >/dev/null
   if [[ $? == 0 ]]  
   then
      cp /var/exam/.netrc.exam_init /root/.netrc
      ftp 192.168.$net.$ip &> /dev/null
      ifconfig eth0 $oldipaddr
   else
      printf "\tWindows XP System IP address must be 192.168.$net.$ip\n"
      sleep 5
      exit 3
   fi
fi
 
rm -rf /root/.netrc
if [[ -d /var/exam/studnet ]]
then
   rm -rf /var/exam/student
fi
 
mkdir /var/exam/student
cp /var/exam/.handin /var/exam/student/Handin
 
#tar xvf exam.tar 1>/dev/null
tar xvf exam.tar >&/dev/null
cp -f handin.conf /var/exam/student/handin.conf
rm -rf exam.tar
rm -rf handin.conf