-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
idletime.sh
36 lines (32 loc) · 964 Bytes
/
idletime.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
36
#!/bin/bash
# Teal Dulcet
# Outputs system idle time
# wget -qO - https://raw.github.com/tdulcet/Distributed-Computing-Scripts/master/idletime.sh | bash -s --
# ./idletime.sh
if [[ $# -ne 0 ]]; then
echo "Usage: $0" >&2
exit 1
fi
# Adapted from: https://github.com/tdulcet/Remote-Servers-Status/blob/master/status.sh
# getSecondsAsDigitalClock <seconds>
getSecondsAsDigitalClock() {
local sec_num=$1
local d=$((sec_num / 86400))
local h=$(((sec_num % 86400) / 3600))
local m=$(((sec_num % 3600) / 60))
local s=$((sec_num % 60))
local text=''
if [[ $d -ne 0 ]]; then
text+="$(printf "%'d" "$d") days "
fi
if [[ $d -ne 0 || $h -ne 0 ]]; then
text+="$h hours "
fi
if [[ $d -ne 0 || $h -ne 0 || $m -ne 0 ]]; then
text+="$m minutes "
fi
text+="$s seconds"
echo "$text"
}
IDLETIME=$(awk '{ print int($2) }' /proc/uptime)
echo -e "System idle time for all processor (CPU) threads since the last boot:\t$(getSecondsAsDigitalClock "$IDLETIME")\n"