Searching...
2011年6月3日 星期五

Radius 測試 - detect.sh (舊版)

這是舊版測試radius服務的script
寫得有點2266....
所以後來就改用比較熟悉的php了
主要就是在radius主機上去對各個連線單位進行radtest測試

其中是讀取檔案
針對檔案的內容來進行測試
檔案的格式為
測試完整帳號 測試密碼 測試ip 測試的單位名稱

完整帳號需包含使用者帳號及後面帶的realm
這邊的測試ip只有 10.1.0.xx 的 xx
主要是因為當時連線單位的數目比較少
然後又有10.1.0.xx及10.100.0.xx兩段
所以就只要輸入最後一個就好



#!/bin/bash

file="/radtest/file2.txt"
savepath="/radtest/"
tempfile=$savepath"2.txt"
testname="預設帳號"
serv=7


seq=1
while read line
do
lines[$seq]=$line
((seq++))
done < $file

echo "下列單位進行Radtest測試發生問題,請盡速查明原因" > $tempfile

count=1

for ((i=1;i<=${#lines[@]};i++))
do #將檔案內容讀至變數
a=$(head -n $i /radtest/file2.txt | tail -1 | awk '{print $1}')
#echo $a
b=$(head -n $i /radtest/file2.txt | tail -1 | awk '{print $2}')
#echo $b
c=$(head -n $i /radtest/file2.txt | tail -1 | awk '{print $3}')
#echo $c
d=$(head -n $i /radtest/file2.txt | tail -1 | awk '{print $4}')
#echo $d

if [ "$a" == "$testname" ] #如果是預設帳號
then
FILESRV=`/usr/bin/radtest $a "$b" 10.1.0.$c 0 金鑰 | grep Accept | grep -c Accept`

if [ $FILESRV -eq 0 ]
then #如果第一段不能的話,試試看第二段可不可以
FILESRV2=`/usr/bin/radtest $a "$b" 10.100.0.$c 0 金鑰 | grep Accept | grep -c Accept`
if [ $FILESRV2 -eq 0 ]
then #如果都不行,ping看看是不是有反應
FILESRV3=`ping -c1 10.1.0.$c | grep 10.1.0.$c | grep -c ttl`

if [ $FILESRV3 -eq 0 ]
then #第一段ping不到,改ping第二段
FILESRV4=`ping -c1 10.100.0.$c | grep 10.100.0.$c | grep -c ttl`
if [ $FILESRV4 -eq 0 ]
then
echo `date`": $d client 10.1.0.$c is error, ping client 10.1.0.$c and 10.100.0.$c failed" >> $tempfile
else
echo `date`": $d client 10.1.0.$c is error, ping client 10.100.0.$c) ok" >> $tempfile
fi
else
echo `date`": $d client 10.1.0.$c is error, ping client 10.1.0.$c ok" >> $tempfile
fi
echo `date`": $d client 10.1.0.$c is error" >> "/radtest/"`date +%Y%m%d`".txt"
count=$((count+1)) #計算有多少失敗
else
echo `date`": $d client 10.100.0.$c is good" >> "/radtest/"`date +%Y%m%d`".txt"
fi
else
echo `date`": $d client 10.1.0.$c is good" >> "/radtest/"`date +%Y%m%d`".txt"
fi
else
FILESRV=`/usr/bin/radtest $a "$b" 10.1.0.7 0 金鑰 | grep Accept | grep -c Accept`
#因為是連線單位提供之測試帳號,由漫遊中心轉過去認證
if [ $FILESRV -eq 0 ]
then #因為不是預設帳號,所以失敗時使用欲設帳號試試看,確認是否是對方外部到內部的問題
FILESRV2=`/usr/bin/radtest 預設帳號 預設密碼 10.1.0.$c 0 金鑰 | grep Accept | grep -c Accept`
if [ $FILESRV2 -eq 0 ]
then
FILESRV3=`ping -c1 10.1.0.$c | grep 10.1.0.$c | grep -c ttl`
if [ $FILESRV3 -eq 0 ]
then
FILESRV4=`ping -c1 10.100.0.$c | grep 10.100.0.$c | grep -c ttl`
if [ $FILESRV4 -eq 0 ]
then
echo `date`": $d client 10.1.0.$c is error, ping client 10.1.0.$c and 10.100.0.$c failed" >> $tempfile
else
echo `date`": $d client 10.1.0.$c is error, ping client 10.100.0.$c) ok" >> $tempfile
fi
else
echo `date`": $d client 10.1.0.$c is error, ping client 10.1.0.$c ok" >> $tempfile
fi

echo `date`": $d client 10.1.0.$c is error" >> "/radtest/"`date +%Y%m%d`".txt"
count=$((count+1))
else
echo `date`": $d client 10.1.0.$c is good" >> "/radtest/"`date +%Y%m%d`".txt"
fi
fi
if [ $FILESRV -eq 1 ]
then
echo `date`": $d client 10.1.0.$c is good" >> "/radtest/"`date +%Y%m%d`".txt"
fi
fi
done

echo "共有 $((count-1)) 間連線單位發生異常" >> $tempfile

/bin/mail -s "radius error information !!" cowman.chiang@gmail.com< $tempfile

0 意見:

張貼留言