跳到主要内容

登录提示脚本

登陆提示效果

================================================================= 

Extranet IP: 8.8.8.8
Private IP: 10.0.8.8
CPU Cores: 2C
Memory: 3.6G
Disk: 59G
CPU Model Name: Intel(R) Xeon(R) Platinum 8255C CPU @ 2.50GHz
OS: CentOS Linux release 7.6.1810 (Core)
Hostname: tencent
Kernel: 3.10.0-1160.62.1.el7.x86_64
Uptime: 14:36:46 up 123 days, 20:08, 1 user, load average: 0.14, 0.07, 0.06
.
=================================================================

脚本内容

cat > /etc/profile.d/motd.sh <<'EOF'
#!/bin/bash

function red_echo(){
echo -e "\033[31;49;1m $1 \033[39;49;0m"
}

function blue_echo(){
echo -e "\033[34;49;1m $1 \033[39;49;0m"
}

inip=`hostname -I | awk '{print $1}'`
exip=`curl -s cip.cc|awk 'NR==1{print $3}'`
mem=`free -h | fgrep "Mem:" | awk '{print $2}'`
cpucores=`cat /proc/cpuinfo | grep processor | wc -l`
osinfo=`cat /etc/redhat-release`
user=`whoami`
time=`date "+%F %T"`
hostname=`hostname`
kernel=`uname -r`
uptime=`uptime | sed -r 's#^[ ]+##g'`
cpu_model_name=`lscpu | grep "^Model name" | awk -F: '{print $2}' | sed -r 's#^[ ]+##g'`
max_disk_size=`df -h | sed 1d | sort -rhk2 | head -1 | awk '{print $2}'`

# 角色、机房、内核、磁盘等
blue_echo "================================================================="
red_echo "
Extranet IP: ${exip}
Private IP: ${inip}
CPU Cores: ${cpucores}C
Memory: ${mem}
Disk: ${max_disk_size}
CPU Model Name: ${cpu_model_name}
OS: ${osinfo}
Hostname: ${hostname}
Kernel: ${kernel}
Uptime: ${uptime}
".
blue_echo "================================================================="

export PS1='[\u@\H \w]\$ '
EOF