77 lines
2.9 KiB
Bash
Executable File
77 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#Script to update motd with relevant information.
|
|
#Define output file
|
|
motd="/etc/motd"
|
|
|
|
|
|
# Collect information
|
|
# $USER is automatically defined
|
|
HOSTNAME=`uname -n`
|
|
KERNEL=`uname -rm`
|
|
INSTALLED_KERNEL=$(pacman -Qi linux | awk '/Version/ { print $3 }')
|
|
CPU=`awk -F '[ :][ :]+' '/^model name/ { print $2; exit; }' /proc/cpuinfo`
|
|
CPU_TEMP=$(($(</sys/class/thermal/thermal_zone0/temp) / 1000))
|
|
#CPU=`uname -p`
|
|
ARCH=`uname -m`
|
|
PACMAN=`pacman -Qu | wc -l`
|
|
DISC=`df -hT | awk '/md0/ {print $4 "/" $3 " (" $6 ")" }'`
|
|
MEMORY=`free -m -t | awk 'NR==2 { printf "%sMB / %sMB\n", $3, $2 }'`
|
|
PSA=`ps -Afl | wc -l`
|
|
PSU=`ps U $USER h | wc -l`
|
|
|
|
#System uptime
|
|
uptime=`cat /proc/uptime | cut -f1 -d.`
|
|
upDays=$((uptime/60/60/24))
|
|
upHours=$((uptime/60/60%24))
|
|
upMins=$((uptime/60%60))
|
|
upSecs=$((uptime%60))
|
|
|
|
|
|
#System load
|
|
LOAD1=`awk {'print $1'} /proc/loadavg`
|
|
LOAD5=`awk {'print $2'} /proc/loadavg`
|
|
LOAD15=`awk {'print $3'} /proc/loadavg`
|
|
|
|
#Color variables
|
|
W="\033[00;37m"
|
|
B="\033[01;36m"
|
|
R="\033[01;34m"
|
|
X="\033[01;37m"
|
|
A="\033[01;32m"
|
|
|
|
#Clear screen before motd
|
|
clear > $motd
|
|
|
|
echo -e "
|
|
$A. $X
|
|
$A/#\ $X _ $A _ _
|
|
$A/###\ $X __ _ _ __ ___| |__ $A| (_)_ __ _ ___ __
|
|
$A/#####\ $X / _' | '__/ __| '_ \ $A| | | '_ \| | | \ \/ /
|
|
$A/##.-.##\ $X | (_| | | | (__| | | |$A| | | | | | |_| |> <
|
|
$A/##( )##\ $X \__,_|_| \___|_| |_|$A|_|_|_| |_|\__,_/_/\_\\
|
|
$A/#.-- --.#\ $X
|
|
$A/' '\ $B
|
|
" >> $motd
|
|
|
|
echo -e "$R===============================================================" >> $motd
|
|
echo -e " $R KERNEL $W= $KERNEL (installed: $INSTALLED_KERNEL) " >> $motd
|
|
echo -e " $R CPU $W= $CPU " >> $motd
|
|
echo -e " $R HOSTNAME $W= $HOSTNAME " >> $motd
|
|
echo -e " $R SYSTEM $W= $PACMAN packages can be updated " >> $motd
|
|
echo -e " $R USERS $W= Currently `users | wc -w` users logged on " >> $motd
|
|
echo -e "$R===============================================================" >> $motd
|
|
echo -e " $R CPU Usage $W= $LOAD1 1 min $LOAD5 5 min $LOAD15 15 min " >> $motd
|
|
echo -e " $R CPU Temperature $W= $CPU_TEMP" >> $motd
|
|
echo -e " $R Memory Used $W= $MEMORY " >> $motd
|
|
echo -e " $R Swap in use $W= `free -m | tail -n 1 | awk '{print $3}'` MB " >> $motd
|
|
echo -e " $R Processes $W= You are running $PSU of $PSA processes " >> $motd
|
|
echo -e " $R System Uptime $W= $upDays days $upHours hours $upMins minutes $upSecs seconds " >> $motd
|
|
echo -e " $R Disk Space Used (md0) $W= $DISC " >> $motd
|
|
echo -e "$R===============================================================" >> $motd
|
|
echo -en "$W" >> $motd
|
|
zpool list >> $motd
|
|
echo -e "$R===============================================================" >> $motd
|
|
script -c "systemctl --failed" /dev/null | grep -E '●| UNIT' >> $motd
|
|
echo -en "$X" >> $motd
|
|
TERM=screen-256color tput sgr0 >> $motd
|