-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw_status
executable file
·110 lines (82 loc) · 2.9 KB
/
w_status
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
# replacement for i3status for my FreeBSD setup
# I want to output
# ue0 | wlan0 | re0 | ZFS | RAM | SWAP | temp | time
interval=1
output_time() {
date "+%d/%m/%Y %H:%M:%S"
}
output_battery() {
read -r bat_state<<<$(echo "$hwstat_output" | awk '$1=="State:" { print $2 }' | tail -n 1)
read -r bat_capacity<<<$(echo "$hwstat_output" | awk '$1=="Remaining" { print $3 }' | head -n 1)
echo "BAT: $bat_capacity% $bat_state"
}
swap_to_mb() {
echo $1 | awk '{ printf "%.2f\n", $1/1024; }'
}
bytes_to_mb() {
echo $1 | awk '{ printf "%.2f\n", $1/1024/1024; }'
}
bytes_to_gb() {
echo $1 | awk '{ printf "%.2f\n", $1/1024/1024/1024; }'
}
output_temp() {
temp=$(echo "$hwstat_output" | awk '$1=="CPU0:" { print $2 }')
echo "t: $temp"
}
output_swap() {
read -r swap_used <<<$(swapinfo | awk 'NR==2 { print $3 }')
echo "SWAP: $(swap_to_mb $swap_used) MiB"
}
output_ram() {
free_output=$(free -h)
read -r ram_all <<<$(echo "$free_output" | awk '$1=="mem_all:" { print $3 }')
read -r ram_used <<<$(echo "$free_output" | awk '$1=="mem_used:" { print $2 }')
echo "RAM: $(bytes_to_gb $ram_used)/$(bytes_to_gb $ram_all) GiB"
}
output_zfs() {
read -r zfs_name zfs_size zfs_free<<<$(zpool list | awk 'NR==2 { print $1,$2,$4 }')
echo "$zfs_name: $zfs_free free"
}
output_eth() {
if_output=$(ifconfig $1 2> /dev/null)
if_ret=$?
read -r status <<<$(echo "$if_output" | awk '$1=="status:" { print $2,$3 }')
if [ "$if_ret" -eq 0 ] && [ "$status" != "no carrier" ]; then
read -r eth_ip<<<$(echo "$if_output" | awk '$1=="inet" { print $2 }')
#read -r eth_type<<<$(echo "$if_output" | awk '$1=="media:" { print $2 }')
read -r eth_media<<<$(echo "$if_output" | awk '$1=="media:" { print $4 }' | sed s/\(//)
echo "$1: $eth_ip $eth_media"
else
echo "$1: offline"
fi
}
output_wlan() {
if_output=$(ifconfig $1 2> /dev/null)
if_ret=$?
read -r status <<<$(echo "$if_output" | awk '$1=="status:" { print $2,$3 }')
if [ "$if_ret" -eq 0 ] && [ "$status" != "no carrier" ]; then
read -r eth_ip<<<$(echo "$if_output" | awk '$1=="inet" { print $2 }')
#read -r eth_type<<<$(echo "$if_output" | awk '$1=="media:" { print $3 }')
#read -r eth_media<<<$(echo "$if_output" | awk '$1=="media:" { print $4 }' | sed s/\(//)
echo "$1: $eth_ip"
else
echo "$1: offline"
fi
}
output_usb_eth() {
if_output=$(ifconfig $1 2> /dev/null)
if_ret=$?
read -r status <<<$(echo "$if_output" | awk '$1=="status:" { print $2,$3 }')
if [ "$if_ret" -eq 0 ] && [ "$status" != "no carrier" ]; then
read -r eth_ip<<<$(echo "$if_output" | awk '$1=="inet" { print $2 }')
echo "$1: $eth_ip"
else
echo "$1: offline"
fi
}
while true; do
hwstat_output=$(hwstat)
echo "$(output_usb_eth ue0) | $(output_wlan wlan0) | $(output_eth re0) | $(output_zfs) | $(output_ram) | $(output_swap) | $(output_temp) | $(output_battery) | $(output_time)";
sleep $interval;
done