码迷,mamicode.com
首页 > 系统相关 > 详细

Linux命令:使用菜单显示简单功能及echo着色

时间:2016-11-03 19:25:34      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:echo   菜单显示   

1.使用菜单显示硬盘,内存,虚拟内存的使用率,且显示使用率超过10%硬盘分区。

#!/bin/bash
#
cat << EOF
d|D) show disk usages.
m|M) show memory usages.
s|S) show swap usages.
*) quit.
EOF


echo -n -e "\033[31mYour choice:\033[0m"
read CHOICE
# read -p "Your choice:" CHOICE

while [ $CHOICE != ‘quit‘ -a $CHOICE != ‘q‘ ] ;do
  case $CHOICE in
  d|D)
     echo "disk usages:"
     df -lh | tee -a ./temp.txt
     ;;  
  m|M)
     echo "Memory usages:"
     free -m | grep "Mem"| tee -a ./temp.txt
     ;;  
  s|S)
     echo "swap usages:"
     free -m | grep -i "swap"| tee -a ./temp.txt
     ;;  
  *)  
     echo "Unknow..."
     ;;    
  esac

  echo -n -e "\033[31mAgain, Your choice:\033[0m"
  read CHOICE

  # read -p "Again, Your choice:" CHOICE

done

TI=`egrep [1-8][0-9]% ./temp.txt | wc -l`
echo " show the total size of disk usage >10% ,A total of $TI datas."
egrep "[1-8][0-9]%" ./temp.txt



[root@localhost ~]# ./showdisk.sh
d|D) show disk usages.
m|M) show memory usages.
s|S) show swap usages.
*) quit.
Your choice:s
swap usages:
Swap:         4094          0       4094
Again, Your choice:d
disk usages:
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5             7.8G  5.2G  2.2G  71% /
/dev/sda11            137G  188M  129G   1% /data
/dev/sda8             3.9G   74M  3.7G   2% /home
/dev/sda7             4.9G  225M  4.4G   5% /var
/dev/sda6             5.9G  141M  5.4G   3% /tmp
/dev/sda3              30G  2.7G   25G  10% /usr
/dev/sda2              49G  180M   46G   1% /u01
/dev/sda1             996M   40M  905M   5% /boot
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/md0              3.8G   72M  3.6G   2% /mnt
Again, Your choice:q
 show the total size of disk usage >10% ,A total of 2 datas.
/dev/sda5             7.8G  5.2G  2.2G  71% /
/dev/sda3              30G  2.7G   25G  10% /usr
[root@localhost ~]#


echo -e "\033[1;32;45mHello\033[0m,world"  

-e \033[1m *** \033[0m 红色部分为固定格式, \033[0m为结束着色;

三组数字用分号(;)分开,绿色1代表加粗,5代表闪烁,可选1-7;

32中3不可变,代表字体着色,2代表七个颜色中绿色,可选1-7;

45中4不可变,代表背景着色,5代表七个颜色中红色,可选1-7;


---end---

Linux命令:使用菜单显示简单功能及echo着色

标签:echo   菜单显示   

原文地址:http://wangfx.blog.51cto.com/1697877/1868933

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!