1#!/bin/bash 2 3read_cfg( ) 4{ 5 cat $1|grep $2|awk '{print $3}' 6 return 7 8} 9 10if [ "$1" == "icqc" ] 11 then 12 :; 13# for user manual 14elif [ "$1" == "h" ] 15 then 16 17echo "=====================================================================================" 18echo "Unload/Reload & scan Flows" 19#echo "Format = ./scan_test.sh <total.times.of.unload/reload> <target.IP.for.pinging> <timeout period> <dev name> <SSID> <PW> <scan times> <Saved file name>" 20echo "Format = ./scan_test.sh <config file> <Saved file name>" 21echo "System Log of each unload/reload will be saved in folder [UnloadReloadScan]" 22echo "=====================================================================================" 23 24 25else 26 # f=failed times; p=passed times 27 declare -i f=0 28 declare -i p=0 29 declare -i pingok=0 30 31 #expired parameter, ready to be removed. 32 declare -i taketime=0 33 34 setting=(total_times_of_unload target_IP_for_pinging timeout_period security device_name SSID PSK_phrase scan_times) 35 36 test ! -f $1 && echo "The cfg file is not existed!!!" 37 for((index=0 ; index < ${#setting[@]} ; index = index + 1)) 38 do 39 VARS[$index]=$(cat $1|grep ${setting[$index]}|awk '{print $3}') 40 #echo $index : ${VARS[$index]} 41 done 42 #exit 0 43 echo "################################################################################" >> $2 44 echo "Unload/Reload test start at : `date`" >> $2 45 echo "Prepare $1 times unload/reload test" 46 mkdir UnloadReloadScan 47 #start test loop, loop count in [i] 48 for ((i = 1 ; i <= ${VARS[0]} ; i = i + 1)) 49 do 50 51 echo "Loading driver..." 52 sleep 2 53 echo "!!!Current round of testing will begin in 3 seconds, please prepare to sniffer packets!!!" 54 sleep 3 55 ./load.sh 56 ./scan_conn.sh ${VARS[4]} ${VARS[5]} ${VARS[6]} ${VARS[7]} ${VARS[3]} & #$4 $5 $6 $7 $3 & 57 # take $3 parameter as the period of [waiting for association ready and DHCP protocol completed]. 58 echo "****** Ping start!! ******" 59 for((w=1;w<=${VARS[2]};w=w+1)) 60 do 61 if ping -W 1 -c 1 ${VARS[1]} >/dev/null; then 62 pingok=1 63 echo "LOOP[$i] : Connection established in $w seconds. (Passed / Failed / Total = $p / $f / ${VARS[0]})" >> $2 64 break 65 else 66 pingok=0 67 fi 68 69 echo $w 70 sleep 1 71 done 72 73 if [ "$pingok" = 1 ]; then 74 pingok=0 75 p=$p+1 76 echo "****** Ping Passed!! (Passed / Failed / Total = $p / $f / ${VARS[0]})******" 77 dmesg -c > "./UnloadReloadScan/Log.of.Passed.Loop[$i].txt" 78 echo "================================================================================" >> "./UnloadReloadScan/Log.of.Passed.Loop[$i].txt" 79 echo "`date` :Interface Information:" >> "./UnloadReloadScan/Log.of.Passed.Loop[$i].txt" 80 ifconfig >> "./UnloadReloadScan/Log.of.Passed.Loop[$i].txt" 81 echo "================================================================================" >> "./UnloadReloadScan/Log.of.Passed.Loop[$i].txt" 82 83 sleep 2 84 else 85 pingok=0 86 f=$f+1 87 echo "LOOP[$i] : Connection establishing timeout ! (Passed / Failed / Total = $p / $f / ${VARS[0]})" >> $2 88 echo "****** Ping Failed!! (Passed / Failed / Total = $p / $f / ${VARS[0]})******" 89 dmesg -c > "./UnloadReloadScan/Log.of.Failed.Loop[$i].txt" 90 echo "================================================================================" >> "./UnloadReloadScan/Log.of.Failed.Loop[$i].txt" 91 echo "`date` :Interface Information:" >> "./UnloadReloadScan/Log.of.Failed.Loop[$i].txt" 92 ifconfig >> "./UnloadReloadScan/Log.of.Failed.Loop[$i].txt" 93 echo "================================================================================" >> "./UnloadReloadScan/Log.of.Failed.Loop[$i].txt" 94 fi 95 96 ./scan_conn.sh ${VARS[4]} ${VARS[5]} off 97 sleep 1 98 echo "unloading driver" 99 ./unload.sh 100 echo "=========================================================" 101 echo "Current loop = $i" 102 echo "Current Result : Passed / Failed / Total = $p / $f / ${VARS[0]}" 103 echo "=========================================================" 104 if [ "$i" = "${VARS[0]}" ]; then 105 echo "All test loops were finished..." 106 echo "Unload/Reload test finished at: `date`" >> $2 107 echo "Result : Passed / Failed / Total = $p / $f / ${VARS[0]}" >> $2 108 echo "################################################################################" >> $2 109 echo " " >> $2 110 else 111 #take a break for next loop. 112 echo "!!!Current round of testing is ended, please stop sniffer packets!!!" 113 sleep 3 114 fi 115 done 116fi 117 118 119 120 121 122 123 124 125 126