Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- # ETHERNET SWITCHES
- 192.168.0.2 SW1
- 192.168.0.3 SW2
- 192.168.0.4 SW3
- # END SWITCHES
- ...
- #!/bin/bash
- DIALOG_CANCEL=1
- DIALOG_ESC=255
- HEIGHT=0
- WIDTH=0
- HOST=`cat /scripts/dialog.out`
- IP=`grep '$HOST' /etc/hosts | awk '{print $1}'`
- display_result() {
- dialog --title "$1"
- --no-collapse
- --msgbox "$result" 0 0
- }
- while true; do
- exec 3>&1
- selection=$(dialog
- --backtitle ""
- --title "MENU"
- --clear
- --cancel-label "EXIT"
- --menu "SELECT OPTION:" $HEIGHT $WIDTH 6
- "1" "SW1"
- "2" "SW2"
- "3" "SW3"
- 2>&1>/scripts/dialog.out 1>&3)
- exit_status=$?
- exec 3>&-
- case $exit_status in
- $DIALOG_CANCEL)
- clear
- exit
- ;;
- $DIALOG_ESC)
- clear
- echo "Program aborted." >&2
- exit 1
- ;;
- esac
- case $selection in
- 0 )
- clear
- echo "Program terminated."
- ;;
- 1 )
- ssh admin@$IP
- ;;
- esac
- done
- --no-items
- Some widgets (checklist, inputmenu, radiolist, menu) display a
- list with two columns (a "tag" and "item", i.e., "description").
- This option tells dialog to read shorter rows, omitting the
- "item" part of the list. This is occasionally useful, e.g., if
- the tags provide enough information.
- See also --no-tags. If both options are given, this one is ig-
- nored.
- --no-tags
- Some widgets (checklist, inputmenu, radiolist, menu) display a
- list with two columns (a "tag" and "description"). The tag is
- useful for scripting, but may not help the user. The --no-tags
- option (from Xdialog) may be used to suppress the column of tags
- from the display. Unlike the --no-items option, this does not
- affect the data which is read from the script.
- Xdialog does not display the tag column for the analogous
- buildlist and treeview widgets; dialog does the same.
- Normally dialog allows you to quickly move to entries on the
- displayed list, by matching a single character to the first
- character of the tag. When the --no-tags option is given, dia-
- log matches against the first character of the description. In
- either case, the matchable character is highlighted.
- sed -e '1,/# ETHERNET SWITCHES/d' -e '/# END SWITCHES/,9999d' /etc/hosts
- #!/bin/bash
- INPUT=/etc/hosts
- let i=0 # define counting variable
- W=() # define working array
- while read -r addr line; do # process file by file
- let i=$i+1
- W+=($addr "$i $line")
- done < <( sed -e '1,/# ETHERNET SWITCHES/d' -e '/# END SWITCHES/,9999d' $INPUT )
- FILE=$(dialog --stdout --no-tags --title "List of Switches in /etc/hosts file" --menu "Chose one" 24 80 17 "${W[@]}" ) # show dialog and store output
- clear
- if [ $? -eq 0 ]; then # Exit with OK
- ssh $FILE
- fi
Add Comment
Please, Sign In to add comment