每天一個小練習--計算一組命令所花費時間

計算一組命令所花費時間。

#cat time_take.sh

#! /bin/bash
#time_take.sh
start=$(date +%s)
for ip in 192.168.2.{1..50}
do
   ping $ip -c 2 &> /dev/null
   if [ $? -eq 0 ]
        then
                echo $ip is alive.
        else
                echo $ip is not alive.
fi
done
end=$(date +%s)
difference=$(( end - start ))
echo Time taken to execute commands is $difference seconds.


參考:linux shell腳本攻略

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章