ssh登录后自动显示系统信息
发布于 分类 Linux
10天前 有1个用户阅读过
登录VPS难免有时候会检测服务器硬盘和内存使用情况,如果1台还能凑合的话,多台就有点繁琐了,这个脚本就是为了解决这个问题!
脚本说明(新手说明):
1.默认手动检测
2.如果需要自动执行,手动执行该脚本后,执行Script Info中对应的3个语句(路径自动匹配)。
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear
#cat <<EOF
###============================================================
### Linux系统信息检测
###------------------------------------------------------------
### Support : All
### Author : noco <http://seonoco.com>
### Update : 2019-12-08 -
###------------------------------------------------------------
### 参考资料
### Bash 脚本实现每次登录到 Shell 时可以查看 Linux 系统信息
### https://linux.cn/article-11645-1.html
### https://www.2daygeek.com/bash-shell-script-view-linux-system-information/
###============================================================
#EOF
cat <<EOF
===============================Script Info Start=============================
# System info on ssh login (demo for centos):
# update: //seonoco.com/blog/system-info-on-ssh-login
# BasePath=$(cd `dirname ${BASH_SOURCE}` ; pwd)
# BaseName=$(basename $BASH_SOURCE)
chmod +x $(cd `dirname ${BASH_SOURCE}` ; pwd)/$(basename $BASH_SOURCE)
echo"$(cd `dirname ${BASH_SOURCE}` ; pwd)/$(basename $BASH_SOURCE)" >> ~root/.bash_profile
source ~root/.bash_profile
===============================Script Info End===============================
EOF
echo -e"-------------------------------System Information----------------------------"
echo -e"Hostname:\t\t"`hostname`
echo -e"uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e"Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e"Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e"Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e"Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e"Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo"VM"; else echo"Physical"; fi`
echo -e"Operating System:\t"`hostnamectl | grep"Operating System" | cut -d ' ' -f5-`
echo -e"Kernel:\t\t\t"`uname -r`
echo -e"Architecture:\t\t"`arch`
echo -e"Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e"Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e"System Main IP:\t\t"`hostname -I`
echo""
echo -e"-------------------------------CPU/Memory Usage------------------------------"
echo -e"Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e"Swap Usage:\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
echo -e"CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' | awk '{print $0}' | head -1`
echo""
echo -e"-------------------------------Disk Usage------------------------------------"
df -Ph
echo""
echo -e"-------------------------------Disk Usage >80%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo""
echo -e"-------------------------------Date------------------------------------------"
echo -e `date`
echo""
echo -e"-------------------------------End-------------------------------------------"
echo""
-- The End --