$more get_wstts_success.sh#!/bin/bashopen_gw_1=$(ssh admin@open-gw-1 "sh /home/admin/bin/check_wstts_success.sh")open_gw_2=$(ssh admin@open-gw-2 "sh /home/admin/bin/check_wstts_success.sh")#echo $open_gw_1#echo $open_gw_2gw_1_all=$(echo $open_gw_1 | cut -d " " -f1)gw_1_err=$(echo $open_gw_1 | cut -d " " -f2)#echo $gw_1_all#echo $gw_1_errgw_2_all=$(echo $open_gw_2 | cut -d " " -f1)gw_2_err=$(echo $open_gw_2 | cut -d " " -f2)#echo $gw_2_all#echo $gw_2_errif [ $gw_1_all -eq 0 ] && [ $gw_2_all -eq 0 ]; then echo 1.00000else successrate=$(echo "scale=5;rate=($gw_1_all + $gw_2_all - $gw_1_err - $gw_2_err) / ($gw_1_all + $gw_2_all);if(length(rate)==scale(rate)) print 0;print rate"|bc) echo $successratefi
第二种实现方法:
awk 'BEGIN{printf "%0.6f",5/6}'