计算一组命令所花费时间。

#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脚本攻略