功能:ping網段中的電腦,有成功的顯示ok
#!/bin/bash
c=10 (c變數指定迴圈開始的值
while [ $c -ne 21 ] (後面的21是迴圈停止的值
do
echo -n 140.137.217."$c" (列印IP
ping -c 1 140.137.217."$c" &>null (將ping的結果丟掉
if [ "$?" == "0" ]; then (用回傳值判斷是否有ping到
echo ok (有ping到就顯示ok
else
echo
fi
c=$(( $c+1 )) (c變數加1
done
===================================
#!/bin/bash
c=10
while [ $c -ne 21 ]
do
echo -n 140.137.217."$c"
ping -c 1 140.137.217."$c" &>null
if [ "$?" == "0" ]; then
echo ok
else
echo
fi
c=$(( $c+1 ))
done
=====================================
沒有留言:
張貼留言