0%

用dialog给Bash穿上衣服

bash下的dialog窗口的实现。

QQ20150526-2@2x](http://jiezhiblog.com/wp-content/uploads/2015/05/QQ20150526-2@2x.png)

QQ20150526-1@2x ](http://jiezhiblog.com/wp-content/uploads/2015/05/QQ20150526-1@2x.png)

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
#!/bin/bash

temp=$(mktemp -t test.XXXXXX)
temp2=$(mktemp -t test2.XXXXXX)

function diskspace {
df -h > $temp
dialog --textbox $temp 20 60
}

function whoseon {
who > $temp
dialog --textbox $temp 20 50
}

function memusage {
cat /proc/meminfo > $temp
diaolog --textbox $temp 20 50
}

while [ 1 ]
do
dialog --menu "Sys Admin Menu" 20 30 10 1 "Display disk space" 2 "Display users" 3 "Dispaly memory usage" 0 "Exi 2> $temp2
if [ $? -eq 1 ]
then
break
fi

selection=$(cat $temp2)
case $selection in
1)
diskspace ;;
2)
whoseon ;;
3)
memusage ;;
0)
break ;;
*)
dialog --msgbox "Sorry, invalid selection" 10 30
esac
done
rm -f $temp 2> /dev/null
rm -f $temp2 2> /dev/null

Welcome to my other publishing channels