期末Linux课程设计(4)―.handin部分

#This Handin 交卷 script
#!/bin/bash
stunum=$(basename $(pwd))
 
set $(echo $stunum|cut -c 8-9)
net=$1
set $(echo $stunum|cut -c 7)
ip=$1
#echo $net   $ip
 
if [[ -f /var/exam/.netrc.handin ]]
then
   cp -f /var/exam/.netrc.handin /root/.netrc
else
   printf "\n\tHand in error! exit\n"
   exit 3
fi
 
if [[ -f /var/exam/student/handin.conf ]]
then
   if [[ -d /var/exam/student/tmp ]]
   then
      rm -rf /var/exam/student/tmp
   fi
   mkdir /var/exam/student/tmp
   set $(cat /var/exam/student/ handin.conf)
   for cp_file in $*    
do
#echo $cp_file
       if [[ -f $cp_file ]]
       then
          cp -f $cp_file /var/exam/student/tmp
       fi
   done
   cd /var/exam/student/tmp
   declare i=0  // 定义变量
   for test_file in $*
   do
       let i=i+1
       if [[ -f test_file ]]
       then
            tar cvf $stunum.tar * 1>/dev/null // 把当前文件夹下所有文件打包
            break
       else
            if [ $i == $# ]
            then
               ls -l /root/$stunum/ > ./$stunum.list
               tar cvf $stunum.tar * 1>/dev/null
            fi
       fi
    done  
    for cp_file in $*
    do
       rm_file=$(basename $cp_file)
       if [[ -f /var/exam/student/tmp/$rm_file ]]
       then
          rm -rf /var/exam/student/tmp/$rm_file
       fi
    done
else
   rm -rf /root/.netrc
   exit 0
fi
ifconfig | head -2 > temp
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
   ftp 192.168.$net.$ip &>/dev/null
   ifconfig eth0 $oldipaddr
else
   ifconfig eth0 192.168.$net.$ip$ip
   ftp 192.168.$net.$ip &>/dev/null
   ifconfig eth0 down
fi
rm -rf /root/.netrc
cd /root/$stunum

你可能感兴趣的:(linux,职场,休闲,考试系统)