teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

修正版コード投稿

2017/12/19 15:37

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -30,4 +30,81 @@
30
30
  no_eps+=("$r_host")
31
31
  fi
32
32
  done < $rfile
33
+ ```
34
+
35
+ あちこちマスクしていますが、修正版のスクリプトです。
36
+ ```ここに言語を入力
37
+ #!/bin/bash
38
+
39
+ rfile='/Backup/result.log'
40
+ declare -a count=()
41
+ declare -a lost_rs=()
42
+ declare -a no_ps=()
43
+ declare -a all_host=()
44
+
45
+ cnt=0
46
+ cnt1=0
47
+ r_chk=0
48
+
49
+ while read line || [ -n "${line}" ];
50
+ do
51
+ if [ `(echo "${line}" |grep -o 'IP')` ];then
52
+ aep=`(echo "${line}" |awk -F ' ' '{print $2}' )`
53
+ all_host+=("${aep}")
54
+ fi
55
+
56
+ if [ `(echo "${line}" | grep -o '^[0-9]*$')` ];then
57
+ cnt=`expr "${cnt}" + 1`
58
+ rpl_count+=("${line}")
59
+ mng=`echo ${count[${#count[@]}-1]}`
60
+ elif [ `(echo "${line}" | grep -o 'SSH')` ];then
61
+ cnt1=`expr "${cnt1}" + 1`
62
+ line=`(echo "${line}" |awk '{print $2}')`
63
+ lost_crs+=("${line}")
64
+ fi
65
+
66
+ if [ "${mng}" = '3' ];then
67
+ mng=`echo ${all_host[${#all_host[@]}-1]}`
68
+ no_eps+=("${mng}")
69
+ fi
70
+
71
+ done < $rfile
72
+
73
+ #echo "This is ${all_host[@]}"
74
+
75
+ for item in ${count[@]};do
76
+ if [ "${item}" = '3' ];then
77
+ r_chk=`expr "${r_chk}" + 1`
78
+
79
+ fi
80
+ done
81
+
82
+ non_ep=$(($cnt * 3))
83
+ total=0
84
+ n=${#count[@]}
85
+ n=$((n - 1))
86
+ while [ "${n}" -ge 0 ];
87
+ do
88
+ total=$((count[$n] + $total))
89
+ r_total=$(($total - $non_ep))
90
+ n=$((n - 1))
91
+ done
92
+ echo "Total Count = $r_total"
93
+ total_cr=`expr "${cnt}" + "${cnt1}"`
94
+ con_rate=`echo "scale=2; 1-($cnt1/$cnt)" | bc`
95
+ con_rate2=`echo "scale=2; $con_rate*100" | bc`
96
+ echo "Connection Rate = $con_rate2 %"
97
+ echo "Number of Connected = $cnt"
98
+ echo -e "\n"
99
+ echo -e "Number without Ps = $r_chk"
100
+ echo -e " -without Ps-\n ${no_es[@]}"
101
+ echo -e "\n"
102
+ echo "Number of Lost = $cnt1"
103
+ #echo -e "\n"
104
+ if [ "${cnt1}" -gt 0 ];then
105
+ echo -e " -Lost Connection-\n ${lost_rs[@]}"
106
+ else
107
+ echo " -All Connected-"
108
+ fi
109
+
33
110
  ```