关键词:dialog 、kdialog
dailog不需要X服务,kdialog需要X服务
方法一(dialog ):
#!/bin/bash # using dialog to create a menu temp=$(mktemp -t test.XXXXXX) temp2=$(mktemp -t test2.XXXXXX) function diskspace { df -k > $temp dialog --textbox $temp 20 60 } function whoseon { who > $temp dialog --textbox $temp 20 50 } function memusage { cat /proc/meminfo > $temp dialog --textbox $temp 20 50 } while [ 1 ] do dialog --menu "Sys Admin Menu" 20 30 10 1 "Display disk space" 2 \ "Display users" 3 "Display memory usage" 0 "Exit" 2> $temp2 #注意这里的重定向与kdialog的不同 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
实现效果:
方法二(kdialog ):
设置X服务地址(WindowsIP:192.168.1.3):
[root@ORACLE ~]# export DISPLAY=192.168.1.3:0.0 (根据本地电脑而定)
[root@ORACLE ~]# export|grep DISPLAY
declare -x DISPLAY="192.168.1.3:0.0"
[root@ORACLE ~]#
脚本:
#!/bin/bash # using kdialog to create a menu temp=$(mktemp -t temp.XXXXXX) temp2=$(mktemp -t temp2.XXXXXX) function diskspace { df -k > $temp kdialog --textbox $temp 1000 10 } function whoseon { who > $temp kdialog --textbox $temp 500 10 } function memusage { cat /proc/meminfo > $temp kdialog --textbox $temp 300 500 } while [ 1 ] do kdialog --menu "Sys Admin Menu" "1" "Display diskspace" "2" "Display \ #注意这里不需要定义长宽高 users" "3" "Display memory usage" "0" "Exit" > $temp2 #注意这里的重定向与dialog的不同 if [ $? -eq 1 ] then break fi selection=$(cat $temp2) case $selection in 1) diskspace ;; 2) whoseon ;; 3) memusage ;; 0) break ;; *) kdialog --msgbox "Sorry, invalid selection" esac done
实现效果: