Skip to content

Commit 1e8ee48

Browse files
committed
added motd files
1 parent a35bc1d commit 1e8ee48

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

motd/20-sysinfo

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# see https://github.com/yboetz/motd/blob/master/20-sysinfo
4+
# get load averages
5+
IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }')
6+
# get free memory
7+
IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'})
8+
# get processes
9+
PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'`
10+
PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
11+
PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}`
12+
PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
13+
# get processors
14+
PROCESSOR_NAME=`grep "model name" /proc/cpuinfo | cut -d ' ' -f3- | awk {'print $0'} | head -1`
15+
PROCESSOR_COUNT=`grep -ioP 'processor\t:' /proc/cpuinfo | wc -l`
16+
# get temp
17+
TEMP=`vcgencmd measure_temp | cut -d "=" -f 2`
18+
19+
W="\e[0;39m"
20+
G="\e[1;32m"
21+
R="\e[1;31m"
22+
Y="\e[0;33m"
23+
24+
echo -e "
25+
${W}system info:
26+
$W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'`
27+
$W Kernel......: $W`uname -sr`
28+
29+
$W Uptime......: $W`uptime -p`
30+
$W Temp........: $Y$TEMP$W
31+
$W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m)
32+
$W Processes...: $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user), $G$PROCESS_ALL$W (total)
33+
34+
$W CPU.........: $W$PROCESSOR_NAME ($G$PROCESSOR_COUNT$W vCPU)
35+
$W Memory......: $G$USED$W used, $G$FREE$W free, $G$TOTAL$W total$W"

motd/35-diskspace

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# see https://github.com/yboetz/motd/blob/master/35-diskspace
4+
# config
5+
max_usage=90
6+
bar_width=50
7+
# colors
8+
white="\e[39m"
9+
green="\e[1;32m"
10+
red="\e[1;31m"
11+
dim="\e[2m"
12+
undim="\e[0m"
13+
14+
# disk usage: ignore zfs, squashfs & tmpfs
15+
mapfile -t dfs < <(df -H -x zfs -x squashfs -x tmpfs -x devtmpfs -x overlay --output=target,pcent,size | tail -n+2)
16+
printf "\ndisk usage:\n"
17+
18+
for line in "${dfs[@]}"; do
19+
# get disk usage
20+
usage=$(echo "$line" | awk '{print $2}' | sed 's/%//')
21+
used_width=$((($usage*$bar_width)/100))
22+
# color is green if usage < max_usage, else red
23+
if [ "${usage}" -ge "${max_usage}" ]; then
24+
color=$red
25+
else
26+
color=$green
27+
fi
28+
# print green/red bar until used_width
29+
bar="[${color}"
30+
for ((i=0; i<$used_width; i++)); do
31+
bar+="="
32+
done
33+
# print dimmmed bar until end
34+
bar+="${white}${dim}"
35+
for ((i=$used_width; i<$bar_width; i++)); do
36+
bar+="="
37+
done
38+
bar+="${undim}]"
39+
# print usage line & bar
40+
echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $1, $2, $3); }' | sed -e 's/^/ /'
41+
echo -e "${bar}" | sed -e 's/^/ /'
42+
done

motd/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Much of this was inspired by https://github.com/yboetz/motd
3+
4+
Raspberry Pi returns the CPU temp via `vcgencmd measure_temp`

0 commit comments

Comments
 (0)