計算shell 腳本的執行時間


# 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM