From 55da16f2463fcded7c55635a254ac7bd32746a0c Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Mon, 19 Apr 2021 13:35:00 +0200 Subject: [PATCH] bunch of improvements --- README.md | 2 +- install.sh | 2 +- scripts/00-basic | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7a49459..e464ddf 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ sudo ./install.sh It is compatible with [update-motd](https://launchpad.net/update-motd) used by Ubuntu. -For all other distributions you will have to add the following line to `/etc/pam.d/sshd`: +For not compatible distributions you will have to add the following line to `/etc/pam.d/sshd`: ``` session optional pam_exec.so stdout /etc/update-motd.d/00-basic diff --git a/install.sh b/install.sh index 0541519..84cef78 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ truncate -s0 /etc/motd # empty native static motd mkdir -p /etc/update-motd.d/ # create dedicated directory following ubuntu cp motd /etc/update-motd.d/ # copy the static motd banner into it chmod -x /etc/update-motd.d/* # disable any existing script -cp scripts/* /etc/update-motd.d/ # enable claranet motd +cp scripts/* /etc/update-motd.d/ # enable claranet motd script echo "For distributions which does not use update-motd (e.g. ubuntu/debian), do not forget to add the following to /etc/pam.d/sshd:" echo "session optional pam_exec.so stdout /etc/update-motd.d/00-basic" diff --git a/scripts/00-basic b/scripts/00-basic index e46a742..54b2018 100755 --- a/scripts/00-basic +++ b/scripts/00-basic @@ -4,24 +4,24 @@ cat $(dirname $0)/motd # get load averages -IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }') +IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(awk '{ print $1,$2,$3 }' /proc/loadavg) # 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 }'` +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` +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 Hostname....: $W${HOSTNAME} -$W Distro......: $W$(cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g') +$W Distro......: $W$(grep "PRETTY_NAME" /etc/*release | 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)