私は、次のシステムコマンドを書いて、希望のICMP応答を与えるWebサイトをpingしました。ruby on railsのpingコマンドからの平均時間を保存する
response = system("ping -c1 www.stackoverflow.com")
応答は、今私は上記の統計から平均時間を格納したい
PING stackoverflow.com (64.34.119.12) 56(84) bytes of data.
64 bytes from stackoverflow.com (64.34.119.12): icmp_req=1 ttl=52 time=336 ms
--- stackoverflow.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 336.699/336.699/336.699/0.000 ms
=> true
as--です。だから私は次のシステムコマンドを打つ。
response_time = system("ping -c 1 www.pintile.com | tail -1| awk '{print $4}' | cut -d '/' -f 2")
これは私に平均時間を与えますが、これをresponse_time変数に格納しません。 response_timeに格納されている値はtrueです。
335.898
=> true
今、私の質問はRESPONSE_TIME変数の平均時間を格納する方法あります?
それは私に同じ出力を提供しますが、私は、レールのコンソールで同じ使用して、システムコマンドを実行したときに、私は質問で述べたように、それは値を格納しません間違いありません。 –
こんにちはスワチ...私の編集を確認してください。 – swati
Yuppはそれが本当に働いた.. Thanx :) –