aboutsummaryrefslogtreecommitdiff
path: root/bin/OpenBSDStatus.sh
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2023-01-28 13:56:42 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2023-01-28 13:56:42 -0500
commit1932fea1cfd34d66ad9681c6d10b5c38415979d5 (patch)
treefaf58ce66777b910791d041496e033f7bc3f028a /bin/OpenBSDStatus.sh
parent5bb3b73496c4e11556d61cb0bc01659b7b53d677 (diff)
downloaddotfiles-1932fea1cfd34d66ad9681c6d10b5c38415979d5.tar.gz
dotfiles-1932fea1cfd34d66ad9681c6d10b5c38415979d5.tar.xz
few tweaks for OpenBSD
Diffstat (limited to 'bin/OpenBSDStatus.sh')
-rwxr-xr-xbin/OpenBSDStatus.sh108
1 files changed, 108 insertions, 0 deletions
diff --git a/bin/OpenBSDStatus.sh b/bin/OpenBSDStatus.sh
new file mode 100755
index 0000000..738f11f
--- /dev/null
+++ b/bin/OpenBSDStatus.sh
@@ -0,0 +1,108 @@
+#!/bin/sh
+timeout=1
+
+_sys_memory() {
+ vmstat | sed -n '$p' | awk '{print $4}'
+}
+
+_sys_uptime() {
+uptime | sed -re's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g'
+}
+
+wireless_info() {
+ _if="$1"
+
+ printf "WiFi: %s %s %s %s" \
+ "$_if" \
+ "$(ifconfig "$_if" | sed -nre 's/^.*nwid ([^ ]+).*$/\1/p')" \
+ "$(ifconfig "$_if" | sed -nre 's/^.* ([^ ]+dBm) .*$/\1/p')" \
+ "$(ifconfig "$_if" | sed -nre 's/^.*inet ([^ ]+).*$/\1/p')"
+}
+
+eth_info() {
+ _if="$1"
+
+ printf "Eth: %s %s %s" \
+ "$_if" \
+ "$(ifconfig "$_if" | sed -nre 's/^.*inet ([^ ]+).*$/\1/p')"
+ "$(ifconfig "$_if" | grep -oE '[0-9]+baseT')"
+}
+
+network_info() {
+ default_if="$(netstat -rnf inet | awk '/^default/{print $8}')"
+
+ if [ -z "$default_if" ] ; then
+ echo "No conn"
+ elif ifconfig "$default_if" | grep -q IEEE802.11 ; then
+ wireless_info "$default_if"
+ else
+ eth_info "$default_if"
+ fi
+}
+
+
+ac_status() {
+ if [ `apm -a` -eq 1 ] ; then
+ echo "charging"
+ else
+ printf "discharging "
+
+ if [ `apm -m` != "unknown" ] ; then
+ minutes="$(apm -m)"
+ hours="$(echo "$minutes"/60 | bc)"
+ hours2="$(echo "$minutes"/60 | bc -l)"
+ minutes="$(echo "(${hours2}-${hours})*60" | bc -l )"
+ printf "%d hours, %d minutes left" "$hours" "$minutes"
+ fi
+ fi
+}
+
+cpu_temp() {
+ sysctl hw.sensors.cpu0.temp0 \
+ | awk -F= '{print $2}' \
+ | cut -d' ' -f 1 \
+ | cut -d'.' -f 1 \
+ | tr -d '\n'
+ printf "c"
+}
+
+cpu_fan() {
+ sysctl hw \
+ | grep fan \
+ | awk -F= '{print $2;exit}' \
+ | cut -d' ' -f 1 \
+ | tr -d '\n'
+ printf "rpm"
+}
+
+get_status_simple() {
+echo \
+ "Volume: $(sndioctl | awk 'BEGIN{FS="="}{if($1 ~ /output.level/){print ($2+0)*100}}') |"\
+ "Fan: $(cpu_fan) |"\
+ "Temp: $(cpu_temp) |"\
+ "Setperf: $(sysctl hw.setperf | awk -F= '{print $2}') |"\
+ "Batt: $(apm -l) $(ac_status)|"\
+ "$(network_info) |"\
+ "$(date '+%m.%d.%Y %H:%M:%S')"
+}
+
+get_status() {
+echo \
+ "Volume: $(sndioctl | awk 'BEGIN{FS="="}{if($1 ~ /output.level/){print ($2+0)*100}}')|"\
+ "Temp: $(sysctl hw.sensors.cpu0.temp0 | awk -F= '{print $2}')|"\
+ "Fan: $(sysctl hw | grep fan | awk -F= '{print $2;exit}')|"\
+ "Cpu Freq: $(sysctl hw.cpuspeed | awk -F= '{print $2}')mhz|"\
+ "Setperf: $(sysctl hw.setperf | awk -F= '{print $2}')|"\
+ "Batt: $(apm -l) $(ac_status)|"\
+ "$(network_info) |"\
+ "Free Mem: $(_sys_memory)|"\
+ "uptime: $(_sys_uptime)|"\
+ "$(date '+%m.%d.%Y %H:%M:%S')"
+}
+
+while true ; do
+
+xsetroot -name "$(get_status_simple)"
+
+sleep "$timeout"
+done