Перед использованием данного скрипта необходимо убедиться, что пакет "figlet" установлен
Вот так при логине будет выглядеть MOTD:
Содержимое скрипта:
#!/bin/bash # ENV GREEN=$(tput setaf 2) BLUE="$(tput setaf 4)" YELLOW="$(tput setaf 4)" PURPLE="$(tput setaf 5)" WHITE=$(tput sgr 0) # System load SPACE_ROOT=`df -Ph | grep -e '/$' | awk '{print $4}' | tr -d '\n'` SPACE_HOME=`df -Ph | grep "/home/" | awk '{print $4}' | tr -d '\n'` RAM_1=`free -t -m | grep "Всего" | awk '{print $3" MB";}'` RAM_2=`free -t -m | grep "Память" | awk '{print $2" MB";}'` LA_1=`cat /proc/loadavg | awk {'print $1'}` LA_5=`cat /proc/loadavg | awk {'print $2'}` LA_15=`cat /proc/loadavg | awk {'print $3'}` clear tput setaf 3 figlet $(hostname) tput sgr 0 echo -e " ===================================================================== $PURPLE INFO $WHITE -$BLUE Hostname$(tput sgr 0)........................: $(tput setaf 2)$HOSTNAME $WHITE -$BLUE Uptime$(tput sgr 0)..........................:$(tput setaf 2)`uptime | cut -d ',' -f1` $WHITE ===================================================================== $PURPLE SOURCES $WHITE -$BLUE CPU usage$WHITE.......................: $GREEN$LA_1, $LA_5, $LA_15 (1, 5, 15 min) $WHITE -$BLUE Memory used$WHITE.....................: $GREEN$RAM_1 / $RAM_2 $WHITE -$BLUE Swap in use$WHITE.....................: $GREEN`free -m | tail -n 1 | awk '{print $3}'` MB $WHITE -$BLUE Disk Space$WHITE (/)..................: $GREEN$SPACE_ROOT remaining $WHITE ===================================================================== "
Для отображения свободного места в других точках монтирования, можно добавить по образу и подобию точки "/"
Применение
Ubuntu:
Достаточно скопировать скрипт в директорию "/etc/update-motd.d/" и разрешить право исполнения.
CentOS:
Нужно отключить в SSHD PrintMotd, для этого открываем файл конфигурации "/etc/ssh/sshd_config", находим:
PrintMotd yes
Меняем на:
PrintMotd no
Перезапускаем службу:
systemctl restart sshd
И копируем скрипт с правами запуска в директорию "/etc/profile.d"
UDP: Расширенный скрипт со статусами сервисов
Содержимое скрипта:
#!/bin/bash # ENV RED=$(tput setaf 1) GREEN=$(tput setaf 2) BLUE="$(tput setaf 4)" YELLOW="$(tput setaf 4)" PURPLE="$(tput setaf 5)" WHITE=$(tput sgr 0) # System load SPACE_ROOT=`df -Ph | grep -e '/$' | awk '{print $4}' | tr -d '\n'` SPACE_HOME=`df -Ph | grep "/home/" | awk '{print $4}' | tr -d '\n'` RAM_1=`free -t -m | grep "Total" | awk '{print $3" MB";}'` RAM_2=`free -t -m | grep "RAM" | awk '{print $2" MB";}'` LA_1=`cat /proc/loadavg | awk {'print $1'}` LA_5=`cat /proc/loadavg | awk {'print $2'}` LA_15=`cat /proc/loadavg | awk {'print $3'}` # Services SERVICES="openvpn@server nginx php-fpm mariadb memcached" clear tput setaf 3 figlet $(hostname) tput sgr 0 echo -e " ===================================================================== $PURPLE INFO $WHITE -$BLUE Hostname$(tput sgr 0)........................: $(tput setaf 2)$HOSTNAME $WHITE -$BLUE Uptime$(tput sgr 0)..........................:$(tput setaf 2)`uptime | cut -d ',' -f1` $WHITE ===================================================================== $PURPLE SOURCES $WHITE -$BLUE CPU usage$WHITE.......................: $GREEN$LA_1, $LA_5, $LA_15 (1, 5, 15 min) $WHITE -$BLUE Memory used$WHITE.....................: $GREEN$RAM_1 / $RAM_2 $WHITE -$BLUE Swap in use$WHITE.....................: $GREEN`free -m | tail -n 1 | awk '{print $3}'` MB $WHITE -$BLUE Disk Space$WHITE (/)..................: $GREEN$SPACE_ROOT remaining $WHITE ===================================================================== $PURPLE SERVICES $WHITE" for i in $SERVICES do if /usr/bin/systemctl status $i | grep -q "Active: active (running)" then i=$(echo $i | cut -d '@' -f1) LENGHT=$(echo $i | wc -c) DOT=$[ 23 - $LENGHT ] echo -e " -$BLUE Service: $WHITE$i" | tr -s '\r\n' '.' for ((n=0;n<$DOT;n++)) do echo '.' | tr -s '\r\n' '.' done echo -e ":$GREEN RUNNING $WHITE" else i=$(echo $i | cut -d '@' -f1) LENGHT=$(echo $i | wc -c) DOT=$[ 23 - $LENGHT ] echo -e " -$BLUE Service: $WHITE$i" | tr -s '\r\n' '.' for ((n=0;n<$DOT;n++)) do echo '.' | tr -s '\r\n' '.' done echo -e ":$RED NOT RUNNING $WHITE" fi done echo "====================================================================="