Linux 下定制终端打印信息

2021-08-10  本文已影响0人  今天有什么新鲜事呀
# 编辑 .bashrc  文件
[root@localhost ~]#  vim /root/.bashrc
#定义变量
RED="\033[31m"
GREEN="\033[32m"
BLUE="\033[34m"
NC="\033[0m"

LOGIN_PWD=`pwd`
LOGIN_DATE=`date`
LOGIN_USERS=`users`
LOGIN_UPTIME=`uptime`
SERVER_IP=`ifconfig | grep 'inet' | head -n 1| awk '{print $2}'`
BMC_IP=`ipmitool lan print 1 | grep "IP Address" | grep -v DHCP | cut -d ':' -f2`
DISK_TOTAL=`df -lh --block-size=1024 | awk '{sum+=$2}END{print sum}'`
DISK_USED=`df -lh --block-size=1024 | awk '{sum+=$3}END{print sum}'`
DISK_AVAIL=`df -lh --block-size=1024 | awk '{sum+=$4}END{print sum}'`
DISK_TOTAL_GB=`echo "scale=2; $DISK_TOTAL/(1024^2)" | bc `
DISK_USED_GB=`echo "scale=2; $DISK_USED/(1024^2)" | bc`
DISK_AVAIL_GB=`echo "scale=2;$DISK_AVAIL/(1024^2)" | bc`

#信息输出
echo -e " "
echo -e "$BLUE +-----------------------------------------------------------------+"
echo -e "$GREEN                               WELCOME!                            "
echo -e "$BLUE +-----------------------------------------------------------------+"
echo -e "$GREEN Server IP: $RED"$SERVER_IP
echo -e "$GREEN BMC IP: $RED"$BMC_IP
echo -e "$GREEN Date: $RED"$LOGIN_DATE
echo -e "$GREEN Users: $RED"$LOGIN_USERS
echo -e "$GREEN Directory: $RED"$LOGIN_PWD
echo -e "$GREEN Uptime: $RED"$LOGIN_UPTIME
echo -e "$BLUE +-----------------------------------------------------------------+"
df -lh | column -c 6 | awk '{printf " \033[22;32m%-15s\t%-8s\t \033[22;31m%-s\t%-s\t%-s\t%-s\n",$1,$6,$2,$3,$4,$5}'
echo -e "$GREEN Total Disk Space: $RED$DISK_TOTAL_GB GB"
echo -e "$GREEN Total Free Space: $RED$DISK_AVAIL_GB GB"
echo -e "$GREEN Total Used Space: $RED$DISK_USED_GB GB"
echo -e "$BLUE +-----------------------------------------------------------------+"
echo -e "$NC"
[root@localhost ~]# source .bashrc
 +-----------------------------------------------------------------+
                               WELCOME!
 +-----------------------------------------------------------------+
 Server IP: 100.14.4.73
 BMC IP:  100.14.0.33
 Date: Tue Aug 10 11:18:41 CST 2021
 Users: root root root
 Directory: /root
 Uptime:  11:18:41 up 17:47, 3 users, load average: 0.21, 0.17, 0.17
 +-----------------------------------------------------------------+
 Filesystem             Mounted          Size   Used    Avail   Use%
 devtmpfs               /dev             252G   0       252G    0%
 tmpfs                  /dev/shm         252G   0       252G    0%
 tmpfs                  /run             252G   22M     252G    1%
 tmpfs                  /sys/fs/cgroup   252G   0       252G    0%
 /dev/mapper/cl-root    /                70G    19G     52G     27%
 /dev/sda2              /boot            1014M  654M    361M    65%
 /dev/sda1              /boot/efi        599M   6.9M    592M    2%
 /dev/mapper/cl-home    /home            372G   17G     356G    5%
 tmpfs                  /run/user/0      51G    0       51G     0%
 Total Disk Space: 1500.36 GB
 Total Free Space: 1464.91 GB
 Total Used Space: 35.45 GB
 +-----------------------------------------------------------------+
上一篇下一篇

猜你喜欢

热点阅读