天天看點

shell之dialog提示視窗

dialog 提示視窗

1.msgbox

    dialog --msgbox text 20 10

2.yesno

    dialog --title "Please answer" --yesno "Is this thing on?" 10 20

    no 傳回值為1,yes為0

3.inputbox

    dialog --inputbox "Enter your age:" 10 20 2>a.txt

    ok 傳回0,cancel傳回1

4.textbox

    dialog --textbox /etc/passwd 15 45

    exit 傳回0

5.menu

    dialog --menu "Sys Admin Menu" 20 30 10 1 "Dislay disk space" 2 "Display users" 2>text.txt

6.fselect

    dialog --title "Select a file" --f  10 50 2>text.txt

shell之dialog提示視窗
shell之dialog提示視窗

mktemp 指令及選項

   沒有選項時建立本地臨時檔案

-t  在系統的臨時目錄/tmp 下建立臨時檔案

-d  建立臨時目錄

 tempfile=`mktemp temp.XXXXXX`                   #檔案名格式 file.XXXXXX  6個大寫X

一個簡單示例程式

#!/bin/bash

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 apace" 2 "Display users" 3 "Display memory usage" 0 "Exit" 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,incalid selection" 10 30
    esac
    done
    rm -f $temp $temp2 2> /dev/null      

轉載請注明出處:http://www.cnblogs.com/tla001/

一起學習,一起進步