-
Notifications
You must be signed in to change notification settings - Fork 0
/
uprecord.sh
executable file
·35 lines (31 loc) · 948 Bytes
/
uprecord.sh
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
30
31
32
33
34
35
#!/bin/bash
if [ -f ~/.uprecord ]
then
uprecord=$(<~/.uprecord)
uprecord=${uprecord%%.*}
#uprecordseconds=$(( uprecord%60 ))
uprecordminutes=$(( uprecord/60%60 ))
uprecordhours=$(( uprecord/60/60%24 ))
uprecorddays=$(( uprecord/60/60/24 ))
else
uprecordminutes=0
uprecordhours=0
uprecorddays=0
fi
uptime=$(</proc/uptime)
uptime=${uptime%%.*}
#seconds=$(( uptime%60 ))
upminutes=$(( uptime/60%60 ))
uphours=$(( uptime/60/60%24 ))
updays=$(( uptime/60/60/24 ))
echo "current uptime:"
echo "${updays}d ${uphours}h ${upminutes}m"
if [[ ( $updays -gt $uprecorddays ) || ( $updays -eq $uprecorddays && $uphours -gt $uprecordhours ) || ( $updays -eq $uprecorddays && $uphours -eq $uprecordhours && $upminutes -gt $uprecordminutes ) ]]
then
echo "new uptime record:"
echo "${updays}d ${uphours}h ${upminutes}m"
cat /proc/uptime > ~/.uprecord
else
echo "old record stands:"
echo "${uprecorddays}d ${uprecordhours}h ${uprecordminutes}m"
fi