Dialog: Ability to dynamically generate a text window, and this window supports numerous window elements.
Dialog: Command
Window elements:
text box
Radio Box
check box
Progress bar
The form that dialog can provide to us, after the selection is completed (after hitting enter), the relevant information is not output to the standard output, but output to the error output
# yum-y Install dialog# Dialog--print-maxsize #这个只是自己的值, for personal size may not be the same, so later set as far as possible do not set the window too large maxsize:35, 134# dialog--b Acktitle "First window"--title "Create User"--yesno "HostName." 10 30
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D8/wKiom1UlEOihR9rNAAEaNwRwGEw427.jpg "title=" 01.png "alt=" Wkiom1uleoihr9rnaaeanwrwgew427.jpg "/>
After the option is pressed to enter
# echo $?0
If you press ENTER after the no option
# echo $?1# dialog--backtitle "First window"--title "Create User"--inputbox "HostName." After #加上 the--inputbox option, you can enter the information
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D4/wKioL1UlEv3i5pTrAAEic7zQ5Mg529.jpg "style=" float: none; "title=" 02.png "alt=" Wkiol1ulev3i5ptraaeic7zq5mg529.jpg "/>
Not yet press ENTER
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D8/wKiom1UlEbXDSd7kAAFBBNkvzYQ946.jpg "style=" float: none; "title=" 03.png "alt=" Wkiom1ulebxdsd7kaafbbnkvzyq946.jpg "/>
# hostname= ' dialog--stdout--backtitle "First Window"--title "Create User"--inputbox "Hostname." 10 30 '
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D4/wKioL1UlGWeDwre6AAEpe3iw68A329.jpg "title=" 05.png "alt=" Wkiol1ulgwedwre6aaepe3iw68a329.jpg "/>
This time, it's not in the back.
# echo $Hostname Hostname
Note: First, all outputs are directed to standard output (--stdout), and a variable is used to get the execution result of the command. In this case, we are able to call in the script
How to use dialog in scripts
Example: Creating a User
# VIM adduser.sh#!/bin/bash#username= ' dialog--stdout--backtitle "Add a user."--title "Username"--inputbox "please Inpu T a username: "Ten" retval=$?if [$RETVAL-eq 0-a-n $Username]; Then #判定 $? If its value is equal to 0 and the user name is not empty Useradd $Username echo $Username | passwd--stdin $Usernamefi # bash-n adduser.sh# bash adduser.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D4/wKioL1UlHWHQuWeqAAC3jFWr9UM034.jpg "title=" 06.png "alt=" Wkiol1ulhwhquweqaac3jfwr9um034.jpg "/>
# vim Adduser.shif [$RETVAL-eq 0-a-N "$Username"]; Then #把 $Username enclose it in quotation marks.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D4/wKioL1UlIG_xx_raAAErJy9IBYM440.jpg "title=" 07.png "alt=" Wkiol1ulig_xx_raaaerjy9ibym440.jpg "/>
In order not to display this information, and if the user exists, what should I do? The user is there, and you can't create a user as soon as you come up.
# Vim Adduser.sh
If [$RETVAL-eq 0-a-N "$Username"] &&! ID $Username &>/dev/null; Then
# bash adduser.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D9/wKiom1UlItmiwVlOAAFD_aOlLt4481.jpg "title=" 08.png "alt=" Wkiom1ulitmiwvloaafd_aollt4481.jpg "/>
Without any information to return, it should be successful. However, it is not known whether the creation was successful or because the user did not create the success, then change
# vim adduser.sh #!/bin/bash#username= ' dialog --stdout --backtitle ' Add a user. " --title "Username" --inputbox "please input a username: " 10 30 ' retval=$?if [ $RETVAL -eq 0 -a -n "$Username" ]; then if ! id $Username & > /dev/null; then useradd $Username echo $Username | passwd --stdin $Username & > /dev/null dialog --backtitle "Add a user." --title "Add a user." --msgbox "Add user $Username finished. " 10 30 else dialog --backtitle "Add a user." --title "Add a user." --msgbox "$Username is already created." 10 30 fifi# bash adduser.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D9/wKiom1UlJILg_mfEAACmq-IbTx0501.jpg "style=" float: none; "title=" 09.png "alt=" Wkiom1uljilg_mfeaacmq-ibtx0501.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D4/wKioL1UlJcvh6Ci3AACJNTDtpl8743.jpg "style=" float: none; "title=" 10.png "alt=" Wkiol1uljcvh6ci3aacjntdtpl8743.jpg "/>
Now to implement the input account, password
# Vim Adduser.sh
#!/bin/bash
#
Username= ' dialog--stdout--backtitle "Add a user."--title "Username"--inputbox "Please input a Username:" 10 30 "
Retval=$?
If [$RETVAL-eq 0-a-N "$Username"]; Then #判定 $? If the value is equal to 0 and the user name is not empty and the user does not exist on the current host
if! ID $Username &>/dev/null; Then
Useradd $Username
pass= ' dialog--stdout--backtitle "Password for $Username"--title "Passward"--passwordbox "Please enter the Password:" 10 30 '
echo $Pass | passwd--stdin $Username &>/dev/null
Dialog--backtitle "Add a user."--title "Add a user."--msgbox "Add user $Username finished." 10 30
Else
Dialog--backtitle "Add a user."--title "Add a user."--msgbox "$Username is already created." 10 30
Fi
Fi
# bash-n Adduser.sh
# bash adduser.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D4/wKioL1UlKnHjpJeuAACZOeuZXxs058.jpg "style=" float: none; "title=" 11.png "alt=" Wkiol1ulknhjpjeuaaczoeuzxxs058.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D9/wKiom1UlKSmgPesxAACRrvHh0ss909.jpg "style=" float: none; "title=" 12.png "alt=" Wkiom1ulksmgpesxaacrrvhh0ss909.jpg "/>
No information is displayed when you enter a password
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D4/wKioL1UlKnGRSD8EAACB8lkV4DE979.jpg "style=" float: none; "title=" 13.png "alt=" Wkiol1ulkngrsd8eaacb8lkv4de979.jpg "/>
If you want users to display the * number when they enter a password
# Vim adduser.sh pass= ' dialog--stdout--backtitle "Password for $Username"--title "Passward"--insecure--passwordbox "P Lease Enter the password: "Ten ' #加入了--insecure options # Bash adduser.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D4/wKioL1UlLATClm6ZAACUnAcXG1c504.jpg "style=" float: none; "title=" 14.png "alt=" Wkiol1ullatclm6zaacunacxg1c504.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D4/wKioL1UlLAST8KbQAACZwIUwH5w871.jpg "style=" float: none; "title=" 15.png "alt=" Wkiol1ullast8kbqaaczwiuwh5w871.jpg "/>
Now it shows the * number.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D9/wKiom1UlKrzyjjNoAACAX9VkHKg737.jpg "style=" float: none; "title=" 16.png "alt=" Wkiom1ulkrzyjjnoaacax9vkhkg737.jpg "/>
What to do if the user does not give the password
# Vim Adduser.sh
# dialog--title "Cal"--calendar "Canlendar" 6 45 8 4 2015
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D6/wKioL1UlSy2zUpmvAAE9Tfa6m44771.jpg "title=" 01.png "alt=" Wkiol1ulsy2zupmvaae9tfa6m44771.jpg "/>
# dialog--title "Checklist"--checklist "yourself" 2 h hight no W width yes
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/DB/wKiom1UlSpniaM5MAACoSy0x7QI250.jpg "title=" 01.png "alt=" Wkiom1ulspniam5maacosy0x7qi250.jpg "/>
# Vim backup.sh#!/bin/bash#dir= ('/etc/httpd '/etc/pam.d '/etc/vsftpd ') source= ' dialog--stdout--title ' backup '-- Checklist "Choose the dir want to Backup:" 3 0/etc/httpd 0 1/ETC/PAM.D 1 2/etc/vsftpd 0 ' echo $SourceSource = ' echo $Source | Tr-d ' "' for I in $Source; Do echo ${dir[$I]}done# bash backup.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/DB/wKiom1UlS2HzkoprAAD-VVnuJSQ922.jpg "title=" 01.png "alt=" Wkiom1uls2hzkopraad-vvnujsq922.jpg "/>
are displayed
"0" "2"/etc/httpd/etc/vsftpd# vim showusage.sh#!/bin/bash #ShowItem = ' dialog --stdout --title ' show usages " --menu " choose the usage you want: " 12 35 6 1 " Show disk usages " 2 " Show physical memory usages " 3 " Show swap usages " 4 " quit "case $ShowItem in "1") df -lh;; " 2 ") free -m | grep " ^me ";;" 3 ") free -m | grep " ^SW ";;" 4 ") exit;; Esac# bash showusage.sh
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5D/DB/wKiom1UlTpfDHjaNAAD9YJT9PpQ191.jpg "style=" Float:none; "title=" 01.png "alt=" wkiom1ultpfdhjanaad9yjt9ppq191.jpg "/>
filesystem size used avail use% mounted on/dev/sda2 48g 23g 24g 50% /tmpfs 1.9G 21M 1.9G 2% /dev/shm/dev/sda1 190M 51M 129M 29% /boot/dev/mapper/myvg-mydata 9.8G 54M 9.2G 1% /mydata# bash showusage.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D6/wKioL1UlT-DzimltAAECnPJR_rc456.jpg "style=" float: none; "title=" 02.png "alt=" Wkiol1ult-dzimltaaecnpjr_rc456.jpg "/>
mem:3776 2483 1292 144 661 575# Bash showusage.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/DB/wKiom1UlTpfCW1rHAADy6dtRbig589.jpg "style=" float: none; "title=" 03.png "alt=" Wkiom1ultpfcw1rhaady6dtrbig589.jpg "/>
swap:9999 182 9817# Vim gauge.sh#!/bin/bash# (for Percent in {1..100};d o echo "XXX" Ech O "Percent: ${percent}%" echo "XXX" echo $Percent sleep 0.2done) | Dialog--clear--gauge "gauge" 8 0# bash gauge.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/DB/wKiom1UlUCvw-xKXAACVVmzj1l0393.jpg "style=" float: none; "title=" 01.png "alt=" Wkiom1ulucvw-xkxaacvvmzj1l0393.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D6/wKioL1UlUXSxa1GXAACW2J8m4sM553.jpg "style=" float: none; "title=" 02.png "alt=" Wkiol1uluxsxa1gxaacw2j8m4sm553.jpg "/>
# dialog--title "Add a user"--form "please input the infomation of new User:" 4 > "Username:" 1 1 "" 1 15 15 0 > "Full Name:" 2 1 "" 2 0 > "Home Dir:" 3 1 "" 3 "0 >" Shell: "4 1" "4 15 15 0
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D6/wKioL1UlUqXAyf4vAAEw3CkvTA4968.jpg "title=" 01.png "alt=" Wkiol1uluqxayf4vaaew3ckvta4968.jpg "/>
This article is from the "three elder brother" blog, please be sure to keep this source http://523958392.blog.51cto.com/9871195/1631380
dialog for getting Started with Windows programming