SSH登錄的時候顯示一些實用信息
阿新 • • 發佈:2017-07-19
shell sshrc
腳本如容如下:
lvse="\033[32m" zise="\033[35m" end="\033[0m" dmidestatus=$(whereis dmidecode | wc -l) totalmemkb=$(cat /proc/meminfo | grep "MemTotal" | awk ‘{print $2}‘) echo -e " "${zise}"System Date:"${end}${lvse}$(date +"%F %T")${end} echo -e " "${zise}"System Name:"${end}${lvse}$([ -f /etc/redhat-release ] && cat /etc/redhat-release || uname -o)${end} echo -e " "${zise}"System machine:"${end}${lvse}$(uname -m)${end} echo -e " "${zise}"System uptime:"${end}${lvse}$(uptime)${end} if [ $dmidestatus -eq 1 ];then echo -e " "${zise}"System Product:"${end}${lvse}$(dmidecode -s system-product-name) ${end};fi if [ $dmidestatus -eq 1 ];then echo -e " "${zise}"System Serial:"${end}${lvse}$(dmidecode -s system-serial-number) ${end};fi echo -e " "${zise}"Login User:"${end}${lvse}$(whoami)${end} echo -e " "${zise}"Login IP:"${end}${lvse}$(w | grep pts | head -n 1 | awk ‘{print $3}‘)${end} echo -e " "${zise}"Cpu:"${end}${lvse}$(cat /proc/cpuinfo | grep "model name" | tail -n 1 | awk -F ":" ‘{print $2}‘ | sed ‘ s/ / /g‘) echo -e " "${zise}"Cpu Core:"${end}${lvse}$(cat /proc/cpuinfo | grep "model name" | wc -l)${end} echo -e " "${zise}"Cpu Count:"${end}${lvse}$(cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l)${end} echo -e " "${zise}"Memory:"${end}${lvse}$((totalmemkb/1000000))" GB"${end} echo -e " "${zise}"interface:"${end}${lvse} $(ip addr show | grep inet | egrep -v "lo$|:" | awk ‘{print $NF,": " $2}‘)${end}
把如上內容放入/etc/ssh/sshrc 文件 如果沒有次文件 就新建,然後退出登錄 重新登陸 顯示如下:
System Date:2017-07-19 14:25:41 System Name:CentOS release 6.5 (Final) System machine:x86_64 System uptime: 14:25:41 up 89 days, 13:35, 2 users, load average: 0.07, 0.04, 0.00 System Product:PowerEdge R610 System Serial:1111111 Login User:root Login IP:2.2.2.2 Cpu: Intel(R) Xeon(R) CPU L5630 @ 2.13GHz Cpu Core:16 Cpu Count:2 Memory:8 interface: em1 : 1.1.1.1/27 em2 : 192.168.1.2/24
本文出自 “記錄過去的美好” 博客,轉載請與作者聯系!
SSH登錄的時候顯示一些實用信息