Linux commands: Use the menu to display simple functions and echo coloring

Source: Internet
Author: User
Tags disk usage egrep

1. Use the menu to display hard disk, memory, virtual memory usage, and display usage over 10% hard disk partitions.

#!/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 '];d o
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



[Email protected] ~]#./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 of2 datas.
/dev/sda5 7.8G 5.2G 2.2G 71%/
/dev/sda3 30G 2.7G 25G 10%/usr
[Email protected] ~]#


echo- e "\033[1; ; $ m Hello\033[0m, World "

- e \033[1m * * * \033[0m Red part is fixed format, \033[0m for end coloring;

The three groups of numbers are separated by semicolons (;), the Green 1 is bold, 5 is blinking, and 1-7 is optional;

32 in 3 immutable, representing font coloring,2 for seven colors in green, optional 1-7;

45 in 4 immutable, representing background coloring,5 for seven colors in red, optional 1-7;


---end---

Linux commands: Use the menu to display simple functions and echo coloring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.