栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

如何登陆Linux显示系统指标system-info.sh

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何登陆Linux显示系统指标system-info.sh

在目录/etc/profile.d增加文件system-info.sh,内容如下:

#/bin/bash
### Welcome to my linux
welcome=$(uname -r)

# Memory
memory_total=$(free -m | awk 'NR==2 { printf($2)}')
if [ $memory_total -gt 0 ]
then
    memory_usage=$(free -m | awk 'NR==2 { printf("%3.1f%%", $3/$2*100)}') 
else
    memory_usage=0.0%
fi

# Swap memory
swap_total=$(free -m | awk 'NR==3 { printf($2)}')
if [ $swap_total -gt 0 ]
then
    swap_mem=$(free -m | awk 'NR==3 { printf("%3.1f%%", $3/$2*100)}')
else
    swap_mem=0.0%
fi

# 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

echo -e "n"
echo -e "Welcome to my Linux $welcomen"
echo -e "System information as of time: tt$time_curn"
echo -e "System load: tt33[0;33;40m$load_average33[0m"
echo -e "Processes: tt$processes"
echo -e "Memory used: tt$memory_usage"
echo -e "Swap used: tt$swap_mem"
echo -e "Usage On: tt$usageof"
for line in $ip_pre
do
            ip_address=${line%/*}
            echo -e "IP address: tt$ip_address"
done
echo -e "Users online: tt$user_num"
if [ -f "/var/infomation/msg.txt" ];then
       pkgnum=$(cat /var/infomation/msg.txt |awk -F':' '{print $2}')
       if [ -n "$pkgnum" ] ;then 
               awk -F":" '{print $1":t"$2}' /var/infomation/msg.txt
       fi
fi

if [ "$whoiam" == "root" ]
then
        echo -e "n"
else
        echo -e "To run a command as administrator(user "root"),use "sudo "."
fi

登陆系统后,会显示

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/461051.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号