pubnix-configs/dynamic-motd.d/10-sysinfo
2023-05-18 08:22:11 +02:00

44 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
#
# 10-sysinfo - generate the system information
# Copyright (c) 2013 Nick Charlton
#
# Authors: Nick Charlton <hello@nickcharlton.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
date=`date`
load=`cat /proc/loadavg | awk '{print $1"/"$2"/"$3}'`
root_usage=`df -h / | awk '/\// {print $(NF-1)}'`
memory_usage=`free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { printf("%3.1f%%", used/total*100)}'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
disk_usage=`df -h / | awk 'NR==2{ printf $3" / "$2}'`
users=`users | wc -w`
time=`uptime -p`
processes=`ps aux | wc -l`
echo "System information as of: $date"
echo "--------------------------------------------------------------"
echo
printf " \t1min/5min/15min\n"
printf "System load:\t%s\t" $load
printf "Uptime:\t\t%s\t\t\t\t%s\n" "$time"
printf "Disk usage:\t\t%s\n" "$disk_usage"
printf "Memory usage:\t%s\t\tSwap usage:\t%s\n" $root_usage $swap_usage
printf "Active Users:\t%s\t\tProcesses:\t%s\n" $users $processes
echo
echo "--------------------------------------------------------------"
echo