Raspberry Pi: Bash-Script zur Anzeige von Hostname, Uptime, Workload, Temperature und Disk Space nach SSH-Login

bash-screenshot

Datei stats-profile-login.sh mit folgendem Inhalt im Home-Verzeichnis anlegen:

#!/bin/sh
 
HOSTNAME=`hostname -f`

UPTIME0=`cut -d. -f1 /proc/uptime`
UPTIME1=$(($UPTIME0/86400))
UPTIME2=$(($UPTIME0/3600%24))
UPTIME3=$(($UPTIME0/60%60))
UPTIME4=$(($UPTIME0%60))

LOADAVG1=`cat /proc/loadavg | awk '{print $1}'`
LOADAVG2=`cat /proc/loadavg | awk '{print $2}'`
LOADAVG3=`cat /proc/loadavg | awk '{print $3}'`

TEMP=`vcgencmd measure_temp | cut -c "6-9"`

TOTALDISK=`df -h | grep 'dev/root' | awk '{print $2}'`
USEDDISK=`df -h | grep 'dev/root' | awk '{print $3}'`
FREEDISK=`df -h | grep 'dev/root' | awk '{print $4}'`

echo "
Hostname......: $HOSTNAME
Uptime........: $UPTIME1 days | $UPTIME2 hours | $UPTIME3 minutes | $UPTIME4 seconds
Workload  ....: $LOADAVG1 (1 min.) | $LOADAVG2 (5 min.) | $LOADAVG3 (15 min.)
Temperature...: $TEMP degrees Celsius
Disk Space....: Total: $TOTALDISK | Used: $USEDDISK | Free: $FREEDISK
"

Skript ausführbar machen:

sudo chmod 777 /home/pi/stats-profile-login.sh

Anschließend die systemweite Profildatei öffnen:

sudo nano /etc/profile

Am Ende der Datei folgende Zeile einfügen:

/home/pi/stats-profile-login.sh