Linux登录界面
- 1. 起因
- 2. 脚本
- 3. 效果
1. 起因
某次刷抖音看到一个博主展示了一个登录页面,觉得蛮好看的.于是自己动手也写一个
2. 脚本
编写脚本/usr/local/bin/login.sh
#!/bin/bash
Current_time=`date '+%Y-%m-%d %H:%M:%S'`
Version=`cat /etc/redhat-release`
Kernel_Version=`uname -r`
Uptime=`uptime|awk '{print $3,$4}'|awk -F',' '{print $1}'`
Ipaddress=`hostname -I|awk '{print $1}'`
Hostname=`hostname|awk '{print $1}'`
Cpu_info=`grep name /proc/cpuinfo |awk -F : '{print ":"$2}'|head -1`
Cpu_used=`top -bn1|grep Cpu|awk '{print $2}'|awk -F'.' '{print $1}'`
Memory=`free -m | grep Mem | awk '{total=$2; free=$4; used=total-free; print used"MB /",total"MB","(" used*100/total "% Used)"}'`
Memory_Total=`free -m | grep Mem | awk '{print $2}'`
Memory_Used=`free -m |grep Mem|awk '{print $2-$4}'`
# 颜色
GREEN='\033[0;32m'
NC='\033[0m'
# 进度条
progress_bar() {
Fraction=$1
if [ $Fraction -lt 2 ];then
Fraction=2
fi
Total=$2
Percentage=($Fraction*100/$Total)
Minus=(50-$Percentage/2)
echo -n "["
echo -n -e ${GREEN}
for ((i=1; i<=$Percentage/2; i++)); do
echo -n "="
done
for ((i=1; i<=Minus; i++)); do
echo -n " "
done
echo -n -e ${NC}
echo -n "]"
echo
}
Filesystem_Row_Total=`df -Th | grep -E 'xfs|ext[0-9]\+|nfs4'|wc -l`
Filesystem_info() {
for i in $Filesystem_Row_Total;do
Mount_point=`df -Th | grep -E 'xfs|ext[0-9]\+|nfs4'|awk 'NR=$i {print $NF}'`
Total=`df -Th | grep -E 'xfs|ext[0-9]\+|nfs4'|awk 'NR=$i {print $3}'`
Used=`df -Th | grep -E 'xfs|ext[0-9]\+|nfs4'|awk 'NR=$i {print $4}'`
Percentage=`df -Th | grep -E 'xfs|ext[0-9]\+|nfs4'|awk 'NR=$i {print $(NF-1)}'|awk -F"%" '{print $1}'`
echo "Mounted: $Mount_point $Total / $Used ( $Percentage% Used )"
progress_bar $Percentage 100
done
}
echo "-------------------------------------------------------------------------------"
echo "[System Info]"
echo
echo "Current Time : ${Current_time}"
echo "Os Version : $Version"
echo "Kernel Version : ${Kernel_Version}"
echo "Uptime : ${Uptime}"
echo "Hostname : ${Hostname}"
echo "Ipaddress : ${Ipaddress}"
echo
echo "[System Performance]"
echo
echo "Cpu ${Cpu_info} , $Cpu_used% used"
echo -n "CPU Used : "
progress_bar $Cpu_used 100
echo "Memory : ${Memory}"
echo -n "Memory Used : "
progress_bar $Memory_Used $Memory_Total
echo
echo "[Filesystem Info]"
echo
Filesystem_info
echo "-------------------------------------------------------------------------------"
如果全局生效在/etc/profile追加,如果是某个用户生效~/.bash_profile中追加
echo '/usr/local/bin/login.sh' >> /etc/profile
3. 效果
但那个框框不知道怎么搞,哪位兄弟如果知道记得告诉我下.