[쉘스크립트] 시간 계산 방법
#!/bin/sh
# 현재시간을 nano초 단위로 얻는다.
time1=`date +%s.%N`
sleep 10
# 현재 시간을 nano초 단위로 얻는다.
time2=`date +%s.%N`
# bc를 이용해서 걸린시간을 계산한다.
diff=`echo “$time2 – $time1” | bc`
echo $diff
————————————————-
#!/bin/sh
cat $PWD/output.log | grep “date :” | sed -e ‘s/start date : //g’ | sed -e ‘s/end date : //g’ | sed -e ‘s/^/”/g’ | sed -e ‘s/$/”/g’ | sed -e ‘s/^/date -d /g’ | sed -e ‘s/$/ +%s/g’ > time_list.tmp
list=`cat time_list.tmp`
etime=`sh ./time_list.tmp | tail -1`
stime=`sh ./time_list.tmp | head -1`
ttime=`echo “$etime – $stime” | bc`
htime=`echo “$ttime/3600” | bc`
mtime=`echo “($ttime/60) – ($htime * 60)” | bc`
stime=`echo “$ttime – (($ttime/60) * 60)” | bc`
echo `cat $PWD/output.log | grep “date :” | head -1`
echo `cat $PWD/output.log | grep “date :” | tail -1`
echo “elapased time : ${htime}h_${mtime}m_${stime}s”
touch “${htime}h_${mtime}m_${stime}s”
2 Responses
… [Trackback]
[…] Information to that Topic: nblog.syszone.co.kr/archives/2885 […]
… [Trackback]
[…] Information to that Topic: nblog.syszone.co.kr/archives/2885 […]