-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_1_test.sh
More file actions
executable file
·104 lines (96 loc) · 2.71 KB
/
Copy path8_1_test.sh
File metadata and controls
executable file
·104 lines (96 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
############################################################################# ##
# Copyright (C) 2010-2011 Cameo Communications, Inc.
############################################################################ ##
#
# -------------------------------------------------------------------------- --
# AUTHOR : EExuke
# FILE NAME : 8_test.sh
# FILE DESCRIPTION : Linux shell script file
# FIRST CREATION DATE : 2020/03/30
# --------------------------------------------------------------------------
# Version : 1.0
# Last Change : 2020/03/30
## ************************************************************************** ##
#!/bin/bash
#-----------------------------------------------------------
# COLOUR VARIABLES
#-----------------------------------------------------------
UNDL="\033[4m" F6_E="\033[0m" B_WT="\033[47m"
F_BL="\033[30m" F_RD="\033[31m" F_GR="\033[32m"
F_YL="\033[33m" F_BU="\033[34m" F_PU="\033[35m"
F_DG="\033[36m" F_WT="\033[37m" B_BL="\033[40m"
B_RE="\033[41m" B_GR="\033[42m" B_YL="\033[43m"
B_BU="\033[44m" B_PR="\033[45m" B_DG="\033[46m"
#-----------------------------------------------------------
# 图形化桌面环境中的脚本编程
#-----------------------------------------------------------
# 创建文本菜单
# 要在 echo 命令中包含非打印字符,必须用 -e 选项
function menu {
clear
echo
echo -e "\t\t\tSys Admin Menu\n" # echo使用非打印字符,必须用 -e 选项
echo -e "\t1. Display disk space"
echo -e "\t2. Display logged on users"
echo -e "\t3. Display memory usage"
echo -e "\t0. Exit menu\n\n"
echo -en "\t\tEnter option: " # -en 会抹去末尾换行符
read -n 1 option # -n 选项只读取一个字符
}
# 实现函数
function diskspace {
clear
df -k
}
function whoseon {
clear
who
}
function memusage {
clear
cat /proc/meminfo
}
# 逻辑函数
while [ 1 ]
do
menu
case $option in
0)
break ;;
1)
diskspace ;;
2)
whoseon ;;
3)
memusage ;;
*)
clear
echo "Sorry, wrong selection" ;;
esac
echo -en "\n\n\t\t\tHit any key to continue"
read -n 1 line
done
clear
#-----------------------------------------------------------------
# select 命令创建菜单
PS3="Enter option: "
select option in "Display disk space" "Display logged on users" \
"Display memory usage" "Exit program"
do
case $option in
"Exit program")
break ;;
"Display disk space")
diskspace ;;
"Display logged on users")
whoseon ;;
"Display memory usage")
memusage ;;
*)
clear
echo "Sorry, wrong selection";;
esac
echo -en "\n\n\t\t\tHit any key to continue"
read -n 1 line
done
clear