linux☞输出个性化开机状态

阅读量: zyh 2020-05-09 20:47:17
Categories: Tags:

前沿

觉得默认的登陆不够给力,无法忽悠机器,用wower的话来说,就是先祖忽悠着你

效果图在此

image-20200515110044304

脚本在此

将脚本放置到 /etc/profile.d/status.sh

#!/bin/bash
# Author: zyh
# 需先安装 toilet 和 cowsay 命令
# yum install epel-release -y
# yum install https://rpmfind.net/linux/openmandriva/4.1/repository/x86_64/unsupported/release/toilet-0.2-3-omv4000.x86_64.rpm cowsay -y

user=$USER
home=$HOME

## blue to echo
function blue(){
	    echo -e "\033[34m[Info] $1\033[0m"
    }


## green to echo
function green(){
	    echo -e "\033[32m[Success] $1\033[0m"
    }

## Error
function red(){
	    echo -e "\033[31m\033[01m[Error] $1\033[0m"
    }

# warning
function yellow(){
	    echo -e "\033[33m\033[01m[Warn] $1\033[0m"
    }

## Error to warning with blink
function bred(){
	    echo -e "\033[31m\033[01m\033[05m[Error] $1\033[0m"
    }

# Error to warning with blink
function byellow(){
	    echo -e "\033[33m\033[01m\033[05m[Warn] $1\033[0m"
    }


publicip=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
localip=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
echo -e "$publicip $localip" | cowsay -f tux | toilet -f term  --gay

# * Check if we're somewhere in /home
if [ ! -d ${home} ];then
		    return 0
fi

# * Calculate last login
lastlog=`lastlog -u ${user} | grep ${user} | awk '{for(i=3;i<=NF;++i) printf("%s ",$i)}'`

# * Print Output
echo " ::::::::::::::::::::::::::::::::::-STATUS-::::::::::::::::::::::::::::::::::"
#  * Check RAM Usages
free_mem_usages=$(awk '/MemTotal/{total=$2}/MemAvailable/{free=$2}END{print free/1024"/"total/1024" MB"}' /proc/meminfo)
app_mem_usages=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}/Buffers/{buffers=$2}/^Cached/{cached=$2}END{print (total-free-buffers-cached)/1024"/"total/1024" MB"}'  /proc/meminfo)
all_mem_usages=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}END{print (total-free)/1024"/"total/1024" MB"}'  /proc/meminfo)
blue " Free Memory : ${free_mem_usages}"
blue " Application Memory Usages : ${app_mem_usages}"
blue " System Memory Usages : ${all_mem_usages}"
# * Check Disk Usages
diskusages=$(df -PH | awk '{printf "%-40s%-15s%-15s%-15s%-15s%-15s\n", $1,$2,$3,$4,$5,$6}')
blue " Disk Usages :"
echo "${diskusages}" | toilet -f term --metal -w 200
# * Check Load Average
loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $(NF-2) $(NF-1) $NF}')
blue " Load Average: $loadaverage"