88 lines
2.4 KiB
Bash
Raw Normal View History

2020-01-07 21:47:23 +08:00
#/bin/bash
2019-12-27 16:58:46 +08:00
#Copyright (c) [2019] Huawei Technologies Co., Ltd.
2020-05-07 15:02:42 +08:00
#generic-release is licensed under the Mulan PSL v2.
#You can use this software according to the terms and conditions of the Mulan PSL v2.
#You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
2019-12-27 16:58:46 +08:00
#THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
#PURPOSE.
2020-05-07 15:02:42 +08:00
#See the Mulan PSL v2 for more details.
2019-12-27 16:58:46 +08:00
# Welcome
welcome=$(uname -r)
# Memory
memory_total=$(cat /proc/meminfo | awk '/^MemTotal:/ {printf($2)}')
memory_free=$(cat /proc/meminfo | awk '/^MemFree:/ { printf($2)}')
buffers=$(cat /proc/meminfo | awk '/^Buffers:/ { printf($2)}')
cached=$(cat /proc/meminfo | awk '/^Cached:/ { printf($2)}')
sreclaimable=$(cat /proc/meminfo | awk '/^SReclaimable:/ { printf($2)}')
swap_total=$(cat /proc/meminfo | awk '/^SwapTotal:/ { printf($2)}')
swap_free=$(cat /proc/meminfo | awk '/^SwapFree:/ { printf($2)}')
2020-03-03 14:42:04 +08:00
if [ $memory_total -gt 0 ]
then
memory_usage=`echo "scale=1; ($memory_total - $memory_free - $buffers - $cached - $sreclaimable) * 100.0 / $memory_total" |bc`
memory_usage="${memory_usage}%"
2020-03-03 14:42:04 +08:00
else
memory_usage=0.0%
fi
2019-12-27 16:58:46 +08:00
# Swap memory
2020-03-03 14:42:04 +08:00
if [ $swap_total -gt 0 ]
then
swap_mem=`echo "scale=1; ($swap_total - $swap_free) * 100.0 / $swap_total" |bc`
swap_mem="${swap_mem}%"
2020-03-03 14:42:04 +08:00
else
swap_mem=0.0%
fi
2019-12-27 16:58:46 +08:00
# Usage
usageof=$(df -h / | awk '/\// {print $(NF-1)}')
# System load
load_average=$(awk '{print $1}' /proc/loadavg)
# WHO I AM
whoiam=$(whoami)
# Time
time_cur=$(date)
# Processes
processes=$(ps aux | wc -l)
# Users
user_num=$(users | wc -w)
# Ip address
ip_pre=""
if [ -x "/sbin/ip" ]
then
ip_pre=$(/sbin/ip a | grep inet | grep -v "127.0.0.1" | grep -v inet6 | awk '{print $2}')
fi
2019-12-27 16:58:46 +08:00
echo -e "\n"
echo -e "Welcome to $welcome\n"
echo -e "System information as of time: \t$time_cur\n"
echo -e "System load: \t\033[0;33;40m$load_average\033[0m"
echo -e "Processes: \t$processes"
echo -e "Memory used: \t$memory_usage"
echo -e "Swap used: \t$swap_mem"
echo -e "Usage On: \t$usageof"
for line in $ip_pre
do
ip_address=${line%/*}
echo -e "IP address: \t$ip_address"
done
echo -e "Users online: \t$user_num"
2019-12-27 16:58:46 +08:00
if [ "$whoiam"=="root" ]
then
echo -e "\n"
2019-12-27 16:58:46 +08:00
else
echo -e "To run a command as administrator(user \"root\"),use \"sudo <command>\"."
2019-12-27 16:58:46 +08:00
fi
2020-03-14 11:45:40 +08:00