-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuptime
More file actions
executable file
·44 lines (32 loc) · 730 Bytes
/
uptime
File metadata and controls
executable file
·44 lines (32 loc) · 730 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#set -x
up=$(uptime -p)
up_w=$(echo $up | grep -Eo "[0-9]+\s*week" | cut -f1 -d' ')
up_d=$(echo $up | grep -Eo "[0-9]+\s*day" | cut -f1 -d' ')
up_h=$(echo $up | grep -Eo "[0-9]+\s*hour" | cut -f1 -d' ')
up_m=$(echo $up | grep -Eo "[0-9]+\s*min" | cut -f1 -d' ')
result=
if [[ -z $up_h ]]; then
up_h=0
fi
if [[ -z $up_m ]]; then
up_m=0
fi
if [[ -n $up_w ]]; then
result=$up_w"w"
fi
if [[ -n $up_d ]]; then
if [[ -n $result ]]; then
result=$(echo "$result, ")
fi
result=$up_d"d"
fi
if [[ -n $result ]]; then
result=$(echo "$result, ")
fi
result=$(echo "$result$up_h")
if [[ -n $result ]]; then
result=$(echo "$result:")
fi
result=$(echo "$result$up_m'")
echo $result;