add update.motd
This commit is contained in:
parent
5828342201
commit
28901424ac
3
update.motd/10-hostname-color
Executable file
3
update.motd/10-hostname-color
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
/usr/bin/env figlet "$(hostname)" | /usr/games/lolcat -f
|
29
update.motd/20-sysinfo
Executable file
29
update.motd/20-sysinfo
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get load averages
|
||||
IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }')
|
||||
# get free memory
|
||||
IFS=" " read USED AVAIL TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$7,$2'})
|
||||
# get processes
|
||||
PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'`
|
||||
PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
|
||||
PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}`
|
||||
PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
|
||||
# get processors
|
||||
PROCESSOR_NAME=`grep "model name" /proc/cpuinfo | cut -d ' ' -f3- | awk {'print $0'} | head -1`
|
||||
PROCESSOR_COUNT=`grep -ioP 'processor\t:' /proc/cpuinfo | wc -l`
|
||||
|
||||
W="\e[0;39m"
|
||||
G="\e[1;32m"
|
||||
|
||||
echo -e "
|
||||
${W}system info:
|
||||
$W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'`
|
||||
$W Kernel......: $W`uname -sr`
|
||||
|
||||
$W Uptime......: $W`uptime -p`
|
||||
$W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m)
|
||||
$W Processes...:$W $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user), $G$PROCESS_ALL$W (total)
|
||||
|
||||
$W CPU.........: $W$PROCESSOR_NAME ($G$PROCESSOR_COUNT$W vCPU)
|
||||
$W Memory......: $G$USED$W used, $G$AVAIL$W avail, $G$TOTAL$W total$W"
|
4
update.motd/20-uptime
Executable file
4
update.motd/20-uptime
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
printf "\n"
|
||||
uptime -p
|
41
update.motd/35-diskspace
Executable file
41
update.motd/35-diskspace
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
# config
|
||||
max_usage=90
|
||||
bar_width=50
|
||||
# colors
|
||||
white="\e[39m"
|
||||
green="\e[1;32m"
|
||||
red="\e[1;31m"
|
||||
dim="\e[2m"
|
||||
undim="\e[0m"
|
||||
|
||||
# disk usage: ignore zfs, squashfs & tmpfs
|
||||
mapfile -t dfs < <(df -H -x zfs -x squashfs -x tmpfs -x devtmpfs -x overlay --output=target,pcent,size | tail -n+2)
|
||||
printf "\ndisk usage:\n"
|
||||
|
||||
for line in "${dfs[@]}"; do
|
||||
# get disk usage
|
||||
usage=$(echo "$line" | awk '{print $2}' | sed 's/%//')
|
||||
used_width=$((($usage*$bar_width)/100))
|
||||
# color is green if usage < max_usage, else red
|
||||
if [ "${usage}" -ge "${max_usage}" ]; then
|
||||
color=$red
|
||||
else
|
||||
color=$green
|
||||
fi
|
||||
# print green/red bar until used_width
|
||||
bar="[${color}"
|
||||
for ((i=0; i<$used_width; i++)); do
|
||||
bar+="="
|
||||
done
|
||||
# print dimmmed bar until end
|
||||
bar+="${white}${dim}"
|
||||
for ((i=$used_width; i<$bar_width; i++)); do
|
||||
bar+="="
|
||||
done
|
||||
bar+="${undim}]"
|
||||
# print usage line & bar
|
||||
echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $1, $2, $3); }' | sed -e 's/^/ /'
|
||||
echo -e "${bar}" | sed -e 's/^/ /'
|
||||
done
|
37
update.motd/40-services
Executable file
37
update.motd/40-services
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# set column width
|
||||
COLUMNS=3
|
||||
# colors
|
||||
green="\e[1;32m"
|
||||
red="\e[1;31m"
|
||||
undim="\e[0m"
|
||||
|
||||
services=("zabbix-server" "zabbix-agent2" "apache2" "mariadb" "fail2ban" "chrony" "sendmail")
|
||||
# sort services
|
||||
IFS=$'\n' services=($(sort <<<"${services[*]}"))
|
||||
unset IFS
|
||||
|
||||
service_status=()
|
||||
# get status of all services
|
||||
for service in "${services[@]}"; do
|
||||
service_status+=($(systemctl is-active "$service"))
|
||||
done
|
||||
|
||||
out=""
|
||||
for i in ${!services[@]}; do
|
||||
# color green if service is active, else red
|
||||
if [[ "${service_status[$i]}" == "active" ]]; then
|
||||
out+="${services[$i]}:,${green}${service_status[$i]}${undim},"
|
||||
else
|
||||
out+="${services[$i]}:,${red}${service_status[$i]}${undim},"
|
||||
fi
|
||||
# insert \n every $COLUMNS column
|
||||
if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then
|
||||
out+="\n"
|
||||
fi
|
||||
done
|
||||
out+="\n"
|
||||
|
||||
printf "\nservices:\n"
|
||||
printf "$out" | column -ts $',' | sed -e 's/^/ /'
|
21
update.motd/50-fail2ban
Executable file
21
update.motd/50-fail2ban
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
logfile='/var/log/fail2ban.log*'
|
||||
mapfile -t lines < <(grep -hioP '(\[[a-z-]+\]) ?(?:restore)? (ban|unban)' $logfile | sort | uniq -c)
|
||||
jails=($(printf -- '%s\n' "${lines[@]}" | grep -oP '\[\K[^\]]+' | sort | uniq))
|
||||
|
||||
out=""
|
||||
for jail in ${jails[@]}; do
|
||||
bans=$(printf -- '%s\n' "${lines[@]}" | grep -iP "[[:digit:]]+ \[$jail\] ban" | awk '{print $1}')
|
||||
restores=$(printf -- '%s\n' "${lines[@]}" | grep -iP "[[:digit:]]+ \[$jail\] restore ban" | awk '{print $1}')
|
||||
unbans=$(printf -- '%s\n' "${lines[@]}" | grep -iP "[[:digit:]]+ \[$jail\] unban" | awk '{print $1}')
|
||||
bans=${bans:-0} # default value
|
||||
restores=${restores:-0} # default value
|
||||
unbans=${unbans:-0} # default value
|
||||
bans=$(($bans+$restores))
|
||||
diff=$(($bans-$unbans))
|
||||
out+=$(printf "$jail, %+3s bans, %+3s unbans, %+3s active" $bans $unbans $diff)"\n"
|
||||
done
|
||||
|
||||
printf "\nfail2ban status (monthly):\n"
|
||||
printf "$out" | column -ts $',' | sed -e 's/^/ /'
|
19
update.motd/50-fail2ban-status
Executable file
19
update.motd/50-fail2ban-status
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# fail2ban-client status to get all jails, takes about ~70ms
|
||||
jails=($(fail2ban-client status | grep "Jail list:" | sed "s/ //g" | awk '{split($2,a,",");for(i in a) print a[i]}'))
|
||||
|
||||
out="jail,failed,total,banned,total\n"
|
||||
|
||||
for jail in ${jails[@]}; do
|
||||
# slow because fail2ban-client has to be called for every jail (~70ms per jail)
|
||||
status=$(fail2ban-client status ${jail})
|
||||
failed=$(echo "$status" | grep -ioP '(?<=Currently failed:\t)[[:digit:]]+')
|
||||
totalfailed=$(echo "$status" | grep -ioP '(?<=Total failed:\t)[[:digit:]]+')
|
||||
banned=$(echo "$status" | grep -ioP '(?<=Currently banned:\t)[[:digit:]]+')
|
||||
totalbanned=$(echo "$status" | grep -ioP '(?<=Total banned:\t)[[:digit:]]+')
|
||||
out+="$jail,$failed,$totalfailed,$banned,$totalbanned\n"
|
||||
done
|
||||
|
||||
printf "\nfail2ban status:\n"
|
||||
printf $out | column -ts $',' | sed -e 's/^/ /'
|
12
update.motd/60-upgrades
Executable file
12
update.motd/60-upgrades
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
printf "\n"
|
||||
number=`apt list --upgradable 2> /dev/null | grep 'upgradable' | wc -l`
|
||||
printf "Available updates : %s\n" $number
|
||||
|
||||
if [ $number -gt 0 ]; then
|
||||
printf "\033[1;31mSystem needs %s updates\033[0m\n" $number
|
||||
apt list --upgradable 2> /dev/null | grep 'upgradable'
|
||||
else
|
||||
printf "\033[1;32mSystem is uptodate\033[0m\n"
|
||||
fi
|
||||
echo
|
Loading…
Reference in New Issue
Block a user