-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimelog
More file actions
executable file
·29 lines (24 loc) · 812 Bytes
/
timelog
File metadata and controls
executable file
·29 lines (24 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# 他のスクリプトの実行時間を測り、timelogに記録します。
# Measure the execution time of other scripts and record it in the timelog.
# Written by Kiku at 20230412.
# define a function to record timelog
timespent() {
spentsec=$((finishsec-startsec))
spenttime=$(date --date @$spentsec "+%T" -u)
if [[ $spentsec -ge 86400 ]]; then
days=$((spentsec/86400))
echo "Time spent was $days day(s) and $spenttime" | tee -a timelog.txt
else
echo "Time spent was $spenttime" | tee -a timelog.txt
fi
echo " " >> timelog.txt
}
# record start time
echo "$1 started at $(date)" | tee timelog.txt
startsec=$(date +%s)
$1
# record finish time and spent time
finishsec=$(date +%s)
echo "$1 finished at $(date)" | tee -a timelog.txt
timespent