Guest User

Untitled

a guest
Nov 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. ...
  2. # ETHERNET SWITCHES
  3. 192.168.0.2 SW1
  4. 192.168.0.3 SW2
  5. 192.168.0.4 SW3
  6. # END SWITCHES
  7. ...
  8.  
  9. #!/bin/bash
  10. DIALOG_CANCEL=1
  11. DIALOG_ESC=255
  12. HEIGHT=0
  13. WIDTH=0
  14. HOST=`cat /scripts/dialog.out`
  15. IP=`grep '$HOST' /etc/hosts | awk '{print $1}'`
  16.  
  17. display_result() {
  18. dialog --title "$1"
  19. --no-collapse
  20. --msgbox "$result" 0 0
  21. }
  22. while true; do
  23. exec 3>&1
  24. selection=$(dialog
  25. --backtitle ""
  26. --title "MENU"
  27. --clear
  28. --cancel-label "EXIT"
  29. --menu "SELECT OPTION:" $HEIGHT $WIDTH 6
  30. "1" "SW1"
  31. "2" "SW2"
  32. "3" "SW3"
  33. 2>&1>/scripts/dialog.out 1>&3)
  34. exit_status=$?
  35. exec 3>&-
  36. case $exit_status in
  37. $DIALOG_CANCEL)
  38. clear
  39. exit
  40. ;;
  41. $DIALOG_ESC)
  42. clear
  43. echo "Program aborted." >&2
  44. exit 1
  45. ;;
  46. esac
  47. case $selection in
  48. 0 )
  49. clear
  50. echo "Program terminated."
  51. ;;
  52. 1 )
  53. ssh admin@$IP
  54. ;;
  55. esac
  56. done
  57.  
  58. --no-items
  59. Some widgets (checklist, inputmenu, radiolist, menu) display a
  60. list with two columns (a "tag" and "item", i.e., "description").
  61. This option tells dialog to read shorter rows, omitting the
  62. "item" part of the list. This is occasionally useful, e.g., if
  63. the tags provide enough information.
  64.  
  65. See also --no-tags. If both options are given, this one is ig-
  66. nored.
  67.  
  68. --no-tags
  69. Some widgets (checklist, inputmenu, radiolist, menu) display a
  70. list with two columns (a "tag" and "description"). The tag is
  71. useful for scripting, but may not help the user. The --no-tags
  72. option (from Xdialog) may be used to suppress the column of tags
  73. from the display. Unlike the --no-items option, this does not
  74. affect the data which is read from the script.
  75.  
  76. Xdialog does not display the tag column for the analogous
  77. buildlist and treeview widgets; dialog does the same.
  78.  
  79. Normally dialog allows you to quickly move to entries on the
  80. displayed list, by matching a single character to the first
  81. character of the tag. When the --no-tags option is given, dia-
  82. log matches against the first character of the description. In
  83. either case, the matchable character is highlighted.
  84.  
  85. sed -e '1,/# ETHERNET SWITCHES/d' -e '/# END SWITCHES/,9999d' /etc/hosts
  86.  
  87. #!/bin/bash
  88. INPUT=/etc/hosts
  89. let i=0 # define counting variable
  90. W=() # define working array
  91. while read -r addr line; do # process file by file
  92. let i=$i+1
  93. W+=($addr "$i $line")
  94. done < <( sed -e '1,/# ETHERNET SWITCHES/d' -e '/# END SWITCHES/,9999d' $INPUT )
  95. 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
  96. clear
  97. if [ $? -eq 0 ]; then # Exit with OK
  98. ssh $FILE
  99. fi
Add Comment
Please, Sign In to add comment