计算shell 脚本的执行时间

2022-11-06,,,

# shell_time.sh

#!/bin/bash

UseTime () {
startTime_s=`date +%s` # 获取从1970-01-01 00:00:00 UTC到现在的秒数
$Command
endTime_s=`date +%s`
sumTime=$[ $endTime_s - $startTime_s ]
echo "$startTime ---> $endTime" "Totl:$sumTime second" >> /tmp/usertime.txt
} hello () {
echo "hello !"
sleep 8
} Command=hello
UseTime $Command
# cat /tmp/usertime.txt
20210303-16:30 ---> 20210303-16:32 Totl:2 minutes
---> Totl: second
---> Totl:8 second

计算shell 脚本执行时间的相关教程结束。

《计算shell 脚本的执行时间.doc》

下载本文的Word格式文档,以方便收藏与打印。