当前位置:网站首页>shell 显示系统信息菜单
shell 显示系统信息菜单
2022-06-09 01:18:00 【ghostwritten】
shell 显示系统信息菜单
1. 一次交互
Read-Menu.sh
#!/usr/bin/env bash
# read-menu: a menu driven system information program
clear
cat << EOF Please Select: 1. Display System Information 2. Display Disk Space 3. Display Home Space Utilization 0. Quit EOF
echo -n 'Enter selection [0-3]: '
read -r sel
case $sel in
0) echo "Program terminated.";;
1) echo "Hostname: $HOSTNAME"; uptime;;
2) df -h;;
3)
if [ "$UID" = 0 ]; then
echo "Home Space Utilization (All Users)"
du -sh /home/*
else
echo "Home Space Utilization ($USER)"
du -sh "$HOME"
fi
;;
*)
echo "Invalid entry." >&2
exit 1
esac
执行:
$ bash read-menu.sh
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 0
Program terminated.
$ bash read-menu.sh
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 1
Hostname: yourdomain.com
04:27:46 up 1 day, 8:40, 2 users, load average: 1.74, 1.66, 1.64
$ bash read-menu.sh
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 2
Filesystem Size Used Avail Use% Mounted on
udev 3.6G 0 3.6G 0% /dev
tmpfs 742M 75M 667M 11% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 19G 19G 0 100% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/mapper/data-lvdata 40G 15G 26G 37% /data
/dev/sda2 976M 220M 690M 25% /boot
overlay 40G 15G 26G 37% /data/docker/overlay2/e0be8abd3b18e4c43604eb7a21bc4a6cd40d26290dcaf126a7ecc4ce4463803f/merged
overlay 40G 15G 26G 37% /data/docker/overlay2/263af3bac5540d800f30cb0302129810f7a12b9c0aa075c5bb5ef9c3e404e694/merged
overlay 40G 15G 26G 37% /data/docker/overlay2/c8c0ac7f5b991aa62b7786dc0adacf00685d03c42556080572936da9053eb89a/merged
tmpfs 742M 0 742M 0% /run/user/0
$ bash read-menu.sh
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 3
Home Space Utilization (All Users)
32K /home/ghostwritten
2. 循环交互
while-menu.sh
#!/bin/bash
# while-menu: a menu driven system information program
DELAY=1 # Number of seconds to display results
while true; do
clear
cat << EOF Please Select: 1. Display System Information 2. Display Disk Space 3. Display Home Space Utilization 0. Quit EOF
read -p "Enter selection [0-3] > "
case "$REPLY" in
0)
break
;;
1)
echo "Hostname: $HOSTNAME"
uptime
;;
2)
df -h
;;
3)
if [[ $(id -u) -eq 0 ]]; then
echo "Home Space Utilization (All Users)"
du -sh /home/*
else
echo "Home Space Utilization ($USER)"
du -sh $HOME
fi
;;
*)
echo "Invalid entry."
;;
esac
sleep "$DELAY"
done
echo "Program terminated."
执行:
$ bash read-menu.sh
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 0
Program terminated.
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 1
Hostname: yourdomain.com
04:27:46 up 1 day, 8:40, 2 users, load average: 1.74, 1.66, 1.64
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 2
Filesystem Size Used Avail Use% Mounted on
udev 3.6G 0 3.6G 0% /dev
tmpfs 742M 75M 667M 11% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 19G 19G 0 100% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/mapper/data-lvdata 40G 15G 26G 37% /data
/dev/sda2 976M 220M 690M 25% /boot
overlay 40G 15G 26G 37% /data/docker/overlay2/e0be8abd3b18e4c43604eb7a21bc4a6cd40d26290dcaf126a7ecc4ce4463803f/merged
overlay 40G 15G 26G 37% /data/docker/overlay2/263af3bac5540d800f30cb0302129810f7a12b9c0aa075c5bb5ef9c3e404e694/merged
overlay 40G 15G 26G 37% /data/docker/overlay2/c8c0ac7f5b991aa62b7786dc0adacf00685d03c42556080572936da9053eb89a/merged
tmpfs 742M 0 742M 0% /run/user/0
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
Enter selection [0-3]: 3
Home Space Utilization (All Users)
32K /home/ghostwritten
边栏推荐
- STM32(X) SD卡协议详解
- A complete set of meta universe elements covering software and hardware, crossing virtual and reality, has been born
- Is it safe for Huishang futures to open an account online? Are there any account opening guidelines?
- Application practice | real time data warehouse construction of Wuyi Yuntong based on Apache Doris
- A collection of commonly used SQL scripts is recommended!
- Fatfs (X): lire et écrire plusieurs octets (mots)
- Optimization practice part - udaf batch calling external requests (02)
- Embedded exam review
- php安装CI框架解决
- How MySQL fetches the latest data after grouping
猜你喜欢

並發性能測試的種類與指標

Blazorise scenario to build high-performance web applications

ORA-01017

Today's sleep quality record 76 points

Unveiling the secrets of Youku bullet screen "rendering technology"

Renewal certificate of kubernetes kubeadm Management Certificate

Simple understanding process of machine learning, basic steps of face recognition

消防应急预案编制与演练及安全宣传、培训,收藏

Django MySQL database (IV)

Goeasy applet instant messaging source v1.1.0/ based on websocket communication service provided by goeasy
随机推荐
What is the correct way to start a thread?
shell 大写转小写
Can I turn on the air conditioner
如何提升代码规范性——嵌入式C编程规范。
A collection of commonly used SQL scripts is recommended!
Kusionstack has a sense of open source | it took two years to break the dilemma of "separating lines like mountains"
flush tables with read lock & information_ schema. processlist
仿抖你妹原版主题源码/仿抖音模式套图WordPress图片主题模板
Hong Kong Securities Regulatory Commission reminds NFT risk
An analysis of SQL query optimization principle: 900w+ data, from 17s to 300ms
STM32(X) SD卡协议详解
FATFS解读(X):字符串函数
Renewal certificate of kubernetes kubeadm Management Certificate
User defined annotation @interface usage understanding - personal notes
La base théorique de l'audio et de la vidéo et les données de recherche de la technologie sous - jacente
[tgcalls] managers who track and debug calls
2022-06-08:找到非负数组中拥有“最大或的结果“的最短子数组,返回最短长度。
FATFS(X):读写多字节(字)
【饭谈】自研测速平台 or 网上平台二次开发
香港证监会提示NFT风险