Below is server status checking code can run on LINUX. 1: #!/bin/sh
2: host=$1
3: server=$2
4:
5: # 현재시간을 nano초 단위로 얻는다.
6: time1=`date +%s.%N`
7: result=`nslookup -timeout=5 -retry=0 $host $server`
8:
9: # checking time out string in output string
10: echo $result | grep "timed out" > /dev/null
11: status=$?
12:
13: # set current time by nano seconds
14: time2=`date +%s.%N`
15:
16: # get the duration by bc(:12)
17: diff=`echo "$time2 - $time1" | bc`
18:
19: # if time out, display FAILURE
20: # if not, display OK
21: # if successful, display reply time
22: if [ $status -eq 0 ]
23: then
24: echo "DNS LOOKUP FAILURE|status=0"
25: else
26: echo "DNS LOOKUP OK|time=$diff status=1"
27: fi
Tags: DateTime EUC-KR UTF8 iconv
|