2
\$\begingroup\$

I wrote a menu in bash to access network equipment, but now there are too many of them to show in one screen to permit selecting one without scrolling up or down. I need it to be improved.

I've considered having two files:

The list of each equipment. Inside this file are the headers and an ID to determine if equipment uses SSH or Telnet.

Allowing entering into two modes: one where each equipment of lists would be printed with a number to allow selecting of any. The other mode allows entering a search mode.

#
#
green='\e[0;32m' # '\e[1;32m' is too bright for white bg.
bred='\e[1;31m' # Red
endColor='\e[0m'
ylw='\e[0;33m' # Yellow

clear

# Display welcome message
echo -e "${ylw}
+--------------------------------------------------------------------------+
                        W   A   R   N   I   N   G
+--------------------------------------------------------------------------+
${endColor}"
#
read -p "Press [Enter] to continue ..."
clear
while :
do
clear
LISTA="${bred}+----------------------------------------------------------------+${endColor}\n
${green}[1] ESP_R7609_MTSO${endColor}\n
${green}[2] ESP_R7609_RIGUERO${endColor}\n
${green}[3] ESP_R7609_SUBASTA${endColor}\n
${green}[4] ESP_R7606_BOLONIA${endColor}\n
${green}[5] ESP_R7609_LINDAVISTA${endColor}\n
${green}[6] ESP_R7609_UCA${endColor}\n
${green}[7] ESP_R7606S_01D${endColor}\n
${green}[8] ESP_R7606S_02D${endColor}\n
${green}[9] ESP_R7606_MTSO_01${endColor}\n
${green}[10] ESP_R7606_MTSO_02${endColor}\n
${green}[11] ESP_R7206_01D${endColor}\n
${green}[12] ESP_R7206_02D${endColor}\n
${green}[13] ESP_R4507_01D${endColor}\n
${green}[14] ESP_R4503_01D${endColor}\n
${green}[15] ESP_R7609S_GRANADA_01${endColor}\n
${green}[16] ESP_R7609S_GRANADA_02${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[30] ESP_MWR2941_BAC${endColor}\n        
${green}[31] ESP_MWR2941_UCA${endColor}\n       
${green}[32] ESP_MWR2941_UCA2${endColor}\n       
${green}[33] ESP_MWR2941_3F${endColor}\n         
${green}[34] ESP_MWR2941_3F2${endColor}\n       
${green}[35] ESP_MWR2941_ERICSSON${endColor}\n             
${green}[36] ESP_MWR2941_CIUDADJARDIN${endColor}\n  
${green}[37] ESP_MWR2941_CATARINA_01${endColor}\n   
${green}[39] ESP_MWR2941_BOLONIA${endColor}\n               
${green}[40] ESP_MWR2941_BOLONIA2${endColor}\n             
${green}[41] ESP_MWR2941_SANJUDAS${endColor}\n            
${green}[42] ESP_MWR2941_UNICA${endColor}\n
${green}[43] ESP_MWR2941_LOMAS_SAN_JUDAS${endColor}\n       
${green}[44] ESP_MWR2941_MASAYA_CENTRO${endColor}\n
${green}[45] ESP_MWR2941_ONDAS_DE_LUZ${endColor}\n
${green}[46] ESP_MWR2941_SANTANA${endColor}\n
${green}[47] ESP_MWR2941_27MAYO${endColor}\n
${green}[48] ESP_MWR2941_MORAZAN${endColor}\n
${green}[49] ESP_MWR2941_MONTEFRESCO_01${endColor}\n
${green}[50] ESP_MWR2941_PENASBLANCAS${endColor}\n
${green}[51] ESP_MWR2941_EAAI${endColor}\n
${green}[52] ESP_MWR2941_VILLAFONTANA${endColor}\n
${green}[53] ESP_MWR2941_LASCOLINAS${endColor}\n
${green}[54] ESP_MWR2941_SISTEMATICA${endColor}\n
${green}[55] ESP_MWR2941_LARREYNAGA${endColor}\n
${green}[56] ESP_MWR2941_SUBASTA${endColor}\n
${green}[57] ESP_MWR2941_PLAZA_ESPANA${endColor}\n
${green}[58] ESP_MWR2941_BANPRO${endColor}\n
${green}[59] ESP_MWR2941_EL_HORNO${endColor}\n
${green}[60] ESP_MWR2941_MTSO_01${endColor}\n
${green}[62] ESP_MWR2941_BUENAVISTA${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[70] ESP_ME3800X_CIUDAD_JARDIN${endColor}\n         
${green}[71] ESP_ME3800X_PLAZA_ESPANA${endColor}\n          
${green}[72] ESP_ME3800X_MONTEFRESCO${endColor}\n           
${green}[74] ESP_ME3750_RIVAS${endColor}\n                 
${green}[75] ESP_ME3750_LEON${endColor}\n                   
${green}[76] ESP_ME3750_CHINANDEGA${endColor}\n             
${green}[77] ESP_ME3800X_ROBLES${endColor}\n                         
${green}[78] ESP_ME3800X_LARREYNAGA${endColor}\n                                
${green}[79] ESP_ME3800X_VILLAFLOR${endColor}\n                                 
${green}[80] ESP_ME3800X_PACAYA${endColor}\n                                    
${green}[81] ESP_ME3800X_3F${endColor}\n                                        
${green}[82] ESP_ME3750_HATO_GRANDE${endColor}\n                                
${green}[83] ESP_ME3750_LAGUNA${endColor}\n                                     
${green}[84] ESP_ME3750_LA_GATEADA${endColor}\n                                 
${green}[85] ESP_ME3750_QUISUCA${endColor}\n                        
${green}[86] ESP_ME3800X_SANMARCOS${endColor}\n
${green}[87] ESP_ME3800X_JINOTEPE${endColor}\n
${green}[88] ESP_ME3750_GRANADA${endColor}\n
${green}[89] ESP_ME3800X_GRTXN${endColor}\n
${green}[90] ESP_ME3600X_RIVAS${endColor}\n
${green}[91] ESP_ME3600X_ESTELI${endColor}\n
${green}[92] ESP_ME3600X_LACUESTA${endColor}\n
${green}[93] ESP_ME3600X_CHICOSLAPA${endColor}\n
${green}[94] ESP_ME3600X_JUIGALPA${endColor}\n
${green}[95] ESP_ME3600X_HATOGRANDE${endColor}\n
${green}[96] ESP_ME3800X_LAPAZCENTRO${endColor}\n
${green}[97] ESP_ME3600X_LASBRISAS${endColor}\n
${green}[98] ESP_ME3800X_LEON${endColor}\n
${green}[99] ESP_ME3800X_CHINANDEGA${endColor}\n
${green}[100] ESP_ME3600X_BUENAVISTA${endColor}\n
${green}[101] ESP_ME3600X_ELHORNO${endColor}\n 
${green}[103] ESP_ME3600X_LALIMA${endColor}\n    
${green}[105] ESP_ME3600X_MATAYAGUAL${endColor}\n
${green}[102] ESP_ME3600X_PENASBLANCAS${endColor}\n
${green}[104] ESP_ME3600X_QUISUCA${endColor}\n
${green}[106] ESP_ME3750_VERACRUZ${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[120] ESP_ME6524_TIPITAPA${endColor}\n
${green}[121] ESP_ME6524_UNICA${endColor}\n
${green}[122] ESP_ME6524_MASAYA${endColor}\n
${green}[123] ESP_ME6524_CATARINA${endColor}\n
${green}[124] ESP_ME6524_CERRO_ORO${endColor}\n
${green}[125] ESP_ME6524_CHONCO${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[130] ESP_NX3048_MTSO${endColor}\n
${green}[131] ESP_NX3048_TIPITAPA${endColor}\n
${green}[132] ESP_NX3048_CHINANDEGA${endColor}\n
${green}[133] ESP_NX3048_CATARINA${endColor}\n
${green}[134] ESP_NX3048_UNICA${endColor}\n
${green}[135] ESP_NX3048_LARREYNAGA${endColor}\n
${green}[136] ESP_NX3064_MTSO_01${endColor}\n
${green}[137] ESP_NX3064_MTSO_02${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[150] ESP_ASR901_ACCEDO${endColor}\n
${green}[151] ESP_ASR901_GRANADA_CAP${endColor}\n
${green}[152] ESP_ASR901_GRANADA_CENTRO${endColor}\n
${green}[153] ESP_ASR901_DIRIOMO${endColor}\n
${green}[154] ESP_ASR901_DIRIOMO_CATARINA${endColor}\n
${green}[155] ESP_ASR901_NIQUINOMO_MASATEPE${endColor}\n
${green}[156] ESP_ASR901_MASATEPE${endColor}\n
${green}[157] ESP_ASR901_SAN_MARCOS_JINOTEPE${endColor}\n
${green}[158] ESP_ASR901_JINOTEPE_CENTRO${endColor}\n
${green}[159] ESP_ASR901_DIRIAMBA_CENTRO${endColor}\n
${green}[160] ESP_ASR901_DIRIAMBA${endColor}\n
${green}[161] ESP_ASR901_LAS_ESQUINAS${endColor}\n
${green}[162] ESP_ASR901_K13_CRTRA_SUR${endColor}\n
${green}[163] ESP_ASR901_COBIRSA2${endColor}\n
${green}[164] ESP_ASR901_ANX_DUCUALI${endColor}\n
${green}[165] ESP_ASR901_ALTAMIRA${endColor}\n
${green}[166] ESP_ASR901_JDE${endColor}\n
${green}[167] ESP_ASR901_AJAXDELGADO${endColor}\n
${green}[168] ESP_ASR901_KATIB${endColor}\n
${green}[169] ESP_ASR901_ONDAS_LUZ_2${endColor}\n
${green}[170] ESP_ASR901_TENDERI${endColor}\n
${green}[171] ESP_ASR901_TENDERI_2${endColor}\n
${green}[172] ESP_ASR901_100N${endColor}\n
${green}[173] ESP_ASR901_ENTRADA_ESQUIPULAS${endColor}\n
${green}[174] ESP_ASR901_COSTARICA${endColor}\n
${green}[175] ESP_ASR901_LASMERCEDES${endColor}\n
${green}[176] ESP_ASR901_UNDPROPOSITO2${endColor}\n
${green}[177] ESP_ASR901_ASTROCARTON${endColor}\n
${green}[178] ESP_ASR901_IVANMONTENEGRO${endColor}\n
${green}[179] ESP_ASR901_LAFUENTE${endColor}\n
${green}[180] ESP_ASR901_NICARAO${endColor}\n
${green}[181] ESP_ASR901_ENTRADA_LASFLORES${endColor}\n
${green}[182] ESP_ASR901_SINACOI${endColor}\n
${green}[183] ESP_ASR901_WASPANSUR${endColor}\n
${green}[184] ESP_ASR901_MASAYA6${endColor}\n
${green}[185] ESP_ASR901_ENACAL${endColor}\n
${green}[186] ESP_ASR901_NUEVODIARIO${endColor}\n
${green}[187] ESP_ASR901_HOLIDAYINN${endColor}\n
${green}[188] ESP_ASR901_ZONAFRANCA${endColor}\n
${green}[189] ESP_ASR901_ANX_VILLAVENEZUELA${endColor}\n
${green}[190] ESP_ASR901_GUANACASTILLO${endColor}\n
${green}[191] ESP_ASR901_SOMOTILLO${endColor}\n
${green}[192] ESP_ASR901_K160${endColor}\n
${green}[193] ESP_ASR901_MINA_LIMON${endColor}\n
${green}[194] ESP_ASR901_SANJUDASPISTA${endColor}\n
${green}[195] ESP_ASR901_SEMEMORIALSANDINO${endColor}\n
${green}[196] ESP_ASR901_VILLAFONTANA_2${endColor}\n
${green}[197] ESP_ASR901_MTSO_01${endColor}\n
${green}[198] ESP_ASR901_CHILTEPE${endColor}\n
${green}[199] ESP_ASR901_K35MSYGRA${endColor}\n
${green}[200] ESP_ASR901_SEBACO${endColor}\n
${green}[201] ESP_ASR901_ROBERRTOHUEMBES${endColor}\n
${green}[202] ESP_ASR901_METROCENTRO2${endColor}\n
${green}[203] ESP_ASR901_WASPAN2PEPSI${endColor}\n
${green}[204] ESP_ASR901_JUZGADOS${endColor}\n
${green}[205] ESP_ASR901_TIENDAEJERCITO${endColor}\n
${green}[206] ESP_ASR901_BATCA${endColor}\n
${green}[207] ESP_ASR901_ABERDEEN${endColor}\n
${green}[208] ESP_ASR901_SAN_RAMON${endColor}\n
${green}[209] ESP_ASR901_OCHOMOGO${endColor}\n
${green}[210] ESP_ASR901_K44MSYGRA${endColor}\n
${green}[211] ESP_ASR901_AGRICORP${endColor}\n
${green}[212] ESP_ASR901_LOSPERROS${endColor}\n
${green}[213] ESP_ASR901_LEON_DISNORTE${endColor}\n
${green}[214] ESP_ASR901_CANAL2${endColor}\n
${green}[215] ESP_ASR901_EDIFICIO_DELTA${endColor}\n
${green}[216] ESP_ASR901_RIVASPARQUECENTRAL${endColor}\n
${green}[217] ESP_ASR901_CASATERAN${endColor}\n
${green}[218] ESP_ASR901_CASAPUEBLOS${endColor}\n
${green}[219] ESP_ASR901_VERACRUZ${endColor}\n
${green}[220] ESP_ASR901_ALTAGRACIA${endColor}\n
${green}[221] ESP_ASR901_ELTUMA${endColor}\n
${green}[222] ESP_ASR901_NANDAIME${endColor}\n
${green}[223] ESP_ASR901_IBW${endColor}\n
${green}[224] ESP_ASR901_INCAE2${endColor}\n
${green}[225] ESP_ASR901_TICOMO${endColor}\n
${green}[226] ESP_ASR901_ENTRADA_TICUANTEPE${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[250] ESP_SWES228_VERACRUZ${endColor}\n
${green}[251] ESP_SWES228_VILLA_FONTANA${endColor}\n
${green}[253] ESP_SWSF302_UCA2${endColor}\n
${green}[254] ESP_SWSF302_ROT_GUEGUENSE${endColor}\n
${green}[255] ESP_SWSF320_PLAYA_ROSADA${endColor}\n
${green}[256] ESP_SWES228_CHIQUILISTAGUA${endColor}\n
${green}[257] ESP_SWES228_MASAYA_CENTRO${endColor}\n
${green}[258] ESP_SWSF302_PTO${endColor}\n
${green}[259] ESP_SWSF302_SANJUDAS${endColor}\n
${green}[260] ESP_SWSF302_SANJUDAS3${endColor}\n
${green}[261] ESP_SWSF302_CRTRA_TICUANTEPE${endColor}\n
${green}[262] ESP_SWSF302_GRANADA_01${endColor}\n
${green}[263] ESP_SWSF302_VERACRUZ3${endColor}\n
${green}[264] ESP_SWES228_ROBERTO_TERAN${endColor}\n
${green}[265] ESP_SWES228_DISCOVERY${endColor}\n
${green}[266] ESP_SWSF302_CIUDAD_DARIO${endColor}\n
${green}[267] ESP_SWSF302_SAPOA${endColor}\n
${green}[268] ESP_SWSF302_ACOYAPA${endColor}\n
${green}[269] ESP_SWSF302_MALPAISILLO${endColor}\n
${green}[270] ESP_SWSF302_SIUNA${endColor}\n
${green}[271] ESP_SWSF302_LOSLLANOS${endColor}\n
${green}[272] ESP_SWSF302_PLAYA_EL_COCO${endColor}\n
${green}[273] ESP_SWSF302_PUERTOSANDINO${endColor}\n
${green}[274] ESP_SWSF302_SANIGNACIOCONCEPCION${endColor}\n
${green}[275] ESP_SWSF302_CUAPA${endColor}\n
${green}[276] ESP_SWSF302_CARDENAS${endColor}\n
${green}[277] ESP_SWSF302_RANCHOGRANDE${endColor}\n
${green}[278] ESP_SWSF302_WIWILINUEVASEGOVIA${endColor}\n
${green}[279] ESP_SWSF302_SALINASGRANDES${endColor}\n
${green}[280] ESP_SWSF302_BOACOVIEJO${endColor}\n
${green}[281] ESP_SWSF302_ESTPOLGRA${endColor}\n
${green}[282] ESP_SWSF302_RAJUENSE${endColor}\n
${green}[283] ESP_SWSF302_ELCOMEJEN${endColor}\n
${green}[284] ESP_SWSF302_JIQUILILLO${endColor}\n
${green}[285] ESP_SWSF302_GRANADA_02${endColor}\n
${green}[286] ESP_SWSF302_PUNTATEONOSTE${endColor}\n
${green}[287] ESP_SWSF302_SANJOSECUSMAPA${endColor}\n
${green}[288] ESP_SWSF302_POLARIS${endColor}\n
${green}[289] ESP_SWSF302_LASTORRES${endColor}\n
${green}[290] ESP_SWSF302_CERROLARGO${endColor}\n
${green}[291] ESP_SWSF302_ALMENDRO${endColor}\n
${green}[292] ESP_SWF302_TICUANTEPE${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[300] ESP_SWIE3010_EL_VIEJO${endColor}\n
${green}[301] ESP_SWIE3010_TIPITAPA4${endColor}\n
${green}[302] ESP_SWIE3010_LOS_VALCANES${endColor}\n
${green}[303] ESP_SWIE3010_ABERDEEN${endColor}\n
${green}[304] ESP_SWIE3010_SBENITO${endColor}\n
${green}[305] ESP_SWIE3010_MBONILLA${endColor}\n
${green}[306] ESP_SWIE3010_TIPITAPA8${endColor}\n
${green}[308] ESP_SWIE3010_MATAGALPA${endColor}\n
${green}[309] ESP_SWIE3010_PACAYA${endColor}\n
${green}[310] ESP_SWIE3010_JINOTEPE${endColor}\n
${green}[311] ESP_SWIE3010_LALIMA${endColor}\n
${green}[312] ESP_SWIE3010_ELTUMA${endColor}\n
${green}[313] ESP_SWIE3010_VILLAFLOR${endColor}\n
${green}[314] ESP_SWIE3010_MASAYA_CENTRO${endColor}\n
${green}[315] ESP_SWIE3010_MONTEFRESCO${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[400] ESP_FWSM_01${endColor}\n
${green}[401] ESP_FWSM_02${endColor}\n
${green}[402] ESP_CAT3550_COFRADIA${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
${green}[500] ESP_MX960_MTSO${endColor}\n
${bred}+----------------------------------------------------------------+${endColor}\n
Enter your menu choice [0 exit]:"
echo -e $LISTA
echo "   Pattern to search:"
read PATRON
echo -e $LISTA | grep -i $PATRON
read yourchoice
case $yourchoice in
1) ssh ESP_R7609S_MTSO;;
2) ssh ESP_R7609_RIGUERO;;
3) telnet ESP_R7609_SUBASTA;;
4) ssh ESP_R7606_BOLONIA;;
5) ssh ESP_R7609_LINDAVISTA;;
6) ssh ESP_R7609_UCA;;
7) ssh ESP_R7606S_01D;;
8) ssh ESP_R7606S_02D;;
9) ssh ESP_R7606_MTSO_01;;
10) ssh ESP_R7606_MTSO_02;;
11) telnet ESP_R7206_01D;;
12) telnet ESP_R7206_02D;;
13) telnet ESP_R4507_01D;;
14) telnet ESP_R4503_01D;;
15) ssh ESP_R7609S_GRANADA_01;;
16) ssh ESP_R7609S_GRANADA_02;;
# MWR2941
30) ssh ESP_MWR2941_BAC;;
31) ssh ESP_MWR2941_UCA;;
32) telnet ESP_MWR2941_UCA2;;
33) telnet ESP_MWR2941_3F;;
34) telnet ESP_MWR2941_3F2;;
35) telnet ESP_MWR2941_ERICSSON;;
36) telnet ESP_MWR2941_CIUDADJARDIN;;
37) telnet ESP_MWR2941_CATARINA_01;;
39) ssh ESP_MWR2941_BOLONIA;;
40) telnet ESP_MWR2941_BOLONIA2;;
41) telnet ESP_MWR2941_SANJUDAS;;
42) telnet ESP_MWR2941_UNICA;;
43) telnet ESP_MWR2941_LOMAS_SAN_JUDAS;;
44) telnet ESP_MWR2941_MASAYA_CENTRO;;
45) telnet ESP_MWR2941_ONDAS_DE_LUZ;;
46) telnet ESP_MWR2941_SANTANA;;
47) telnet ESP_MWR2941_27MAYO;;
48) telnet ESP_MWR2941_MORAZAN;;
49) telnet ESP_MWR2941_MONTEFRESCO_01;;
50) ssh ESP_MWR2941_PENASBLANCAS;;
51) telnet ESP_MWR2941_EAAI;;
52) telnet ESP_MWR2941_VILLAFONTANA;;
53) ssh ESP_MWR2941_LASCOLINAS;;
54) telnet ESP_MWR2941_SISTEMATICA;;
55) telnet ESP_MWR2941_LARREYNAGA;;
56) telnet ESP_MWR2941_SUBASTA;;
57) telnet ESP_MWR2941_PLAZA_ESPANA;;
58) telnet ESP_MWR2941_BANPRO;;
59) telnet ESP_MWR2941_EL_HORNO;;
60) telnet ESP_MWR2941_MTSO_01;;
62) telnet ESP_MWR2941_BUENAVISTA;;
# SW ME 3600 / 3750 / 3800
70) ssh ESP_ME3800X_CIUDAD_JARDIN;;
71) ssh ESP_ME3800X_PLAZA_ESPANA;;
72) ssh ESP_ME3800X_MONTEFRESCO;;
74) ssh ESP_ME3750_RIVAS;;
75) ssh ESP_ME3750_LEON;;
76) ssh ESP_ME3750_CHINANDEGA;;
77) ssh ESP_ME3800X_ROBLES;;
78) ssh ESP_ME3800X_LARREYNAGA;;
79) ssh ESP_ME3800X_VILLAFLOR;;
80) ssh ESP_ME3800X_PACAYA;;
81) ssh ESP_ME3800X_3F;;
82) ssh ESP_ME3750_HATO_GRANDE;;
83) ssh ESP_ME3750_LAGUNA;;
84) ssh ESP_ME3750_LA_GATEADA;;
85) ssh ESP_ME3750_QUISUCA;;
86) ssh ESP_ME3800X_SANMARCOS;;
87) ssh ESP_ME3800X_JINOTEPE;;
88) ssh ESP_ME3750_GRANADA;;
89) ssh ESP_ME3800X_GRTXN;;
90) ssh ESP_ME3600X_RIVAS;;
91) ssh ESP_ME3600X_ESTELI;;
92) ssh ESP_ME3600X_LACUESTA;;
93) ssh ESP_ME3600X_CHICOSLAPA;;
94) ssh ESP_ME3600X_JUIGALPA;;
95) ssh ESP_ME3600X_HATOGRANDE;;
96) ssh ESP_ME3800X_LAPAZCENTRO;;
97) ssh ESP_ME3600X_LASBRISAS;;
98) ssh ESP_ME3800X_LEON;;
99) ssh ESP_ME3800X_CHINANDEGA;;
100) ssh ESP_ME3600X_BUENAVISTA;;
101) ssh ESP_ME3600X_ELHORNO;;
102) ssh ESP_ME3600X_PENASBLANCAS;;
103) telnet ESP_ME3600X_LALIMA;;
104) ssh ESP_ME3600X_QUISUCA;;
105) ssh ESP_ME3800X_MATAYAGUAL;;
106) ssh ESP_ME3750_VERACRUZ;;
# SW ME 6500
120) ssh ESP_ME6524_TIPITAPA;;
121) ssh ESP_ME6524_UNICA;;
122) ssh ESP_ME6524_MASAYA;;
123) ssh ESP_ME6524_CATARINA;;
124) ssh ESP_ME6524_CERRO_ORO;;
125) ssh ESP_ME6524_CHONCO;;
# NEXUS
130) ssh ESP_NX3048_MTSO;;
131) ssh ESP_NX3048_TIPITAPA;;
132) ssh ESP_NX3048_CHINANDEGA;;
133) ssh ESP_NX3048_CATARINA;;
134) ssh ESP_NX3048_UNICA;;
135) ssh ESP_NX3048_LARREYNAGA;;
136) ssh ESP_NX3064_MTSO_01;;
137) ssh ESP_NX3064_MTSO_02;;
# ASR901
150) ssh ESP_ASR901_ACCEDO;;
151) ssh ESP_ASR901_GRANADA_CAP;;
152) ssh ESP_ASR901_GRANADA_CENTRO;;
153) ssh ESP_ASR901_DIRIOMO;;
154) ssh ESP_ASR901_DIRIOMO_CATARINA;;
155) ssh ESP_ASR901_NIQUINOMO_MASATEPE;;
156) ssh ESP_ASR901_MASATEPE;;
157) ssh ESP_ASR901_SAN_MARCOS_JINOTEPE;;
158) ssh ESP_ASR901_JINOTEPE_CENTRO;;
159) ssh ESP_ASR901_DIRIAMBA_CENTRO;;
160) ssh ESP_ASR901_DIRIAMBA;;
161) ssh ESP_ASR901_LAS_ESQUINAS;;
162) ssh ESP_ASR901_K13_CRTRA_SUR;;
163) ssh ESP_ASR901_COBIRSA2;;
164) ssh ESP_ASR901_ANX_DUCUALI;;
165) ssh ESP_ASR901_ALTAMIRA;;
166) ssh ESP_ASR901_JDE;;
167) ssh ESP_ASR901_AJAXDELGADO;;
168) ssh ESP_ASR901_KATIB;;
169) ssh ESP_ASR901_ONDAS_LUZ_2;;
170) ssh ESP_ASR901_TENDERI;;
171) ssh ESP_ASR901_TENDERI_2;;
172) ssh ESP_ASR901_100N;;
173) ssh ESP_ASR901_ENTRADA_ESQUIPULAS;;
174) ssh ESP_ASR901_COSTARICA;;
175) ssh ESP_ASR901_LASMERCEDES;;
176) ssh ESP_ASR901_UNDPROPOSITO2;;
177) ssh ESP_ASR901_ASTROCARTON;;
178) ssh ESP_ASR901_IVANMONTENEGRO;;
179) ssh ESP_ASR901_LAFUENTE;;
180) ssh ESP_ASR901_NICARAO;;
181) ssh ESP_ASR901_ENTRADA_LASFLORES;;
182) ssh ESP_ASR901_SINACOI;;
183) ssh ESP_ASR901_WASPANSUR;;
184) ssh ESP_ASR901_MASAYA6;;
185) ssh ESP_ASR901_ENACAL;;
186) ssh ESP_ASR901_NUEVODIARIO;;
187) ssh ESP_ASR901_HOLIDAYINN;;
188) ssh ESP_ASR901_ZONAFRANCA;;
189) ssh ESP_ASR901_ANX_VILLAVENEZUELA;;
190) ssh ESP_ASR901_GUANACASTILLO;;
191) ssh ESP_ASR901_SOMOTILLO;;
192) ssh ESP_ASR901_K160;;
193) ssh ESP_ASR901_MINA_LIMON;;
194) ssh ESP_ASR901_SANJUDASPISTA;;
195) ssh ESP_ASR901_SEMEMORIALSANDINO;;
196) ssh ESP_ASR901_VILLAFONTANA2;;
197) ssh ESP_ASR901_MTSO_01;;
198) ssh ESP_ASR901_CHILTEPE;;
199) ssh ESP_ASR901_K35MSYGRA;;
200) ssh ESP_ASR901_SEBACO;;
201) ssh ESP_ASR901_ROBERTOHUEMBES;;
202) ssh ESP_ASR901_METROCENTRO2;;
203) ssh ESP_ASR901_WASPAN2PEPSI;;
204) ssh ESP_ASR901_JUZGADOS;;
205) ssh ESP_ASR901_TIENDAEJERCITO;;
206) ssh ESP_ASR901_BATCA;;
207) ssh ESP_ASR901_ABERDEEN;;
208) ssh ESP_ASR901_SAN_RAMON;;
209) ssh ESP_ASR901_OCHOMOGO;;
210) ssh ESP_ASR901_K44MSYGRA;;
211) ssh ESP_ASR901_AGRICORP;;
212) ssh ESP_ASR901_LOSPERROS;;
213) ssh ESP_ASR901_LEON_DISNORTE;;
214) ssh ESP_ASR901_CANAL2;;
215) ssh ESP_ASR901_EDIFICIO_DELTA;;
216) ssh ESP_ASR901_RIVASPARQUECENTRAL;;
217) ssh ESP_ASR901_CASATERAN;;
218) ssh ESP_ASR901_CASAPUEBLOS;;
219) ssh ESP_ASR901_VERACRUZ;;
220) ssh ESP_ASR901_ALTAGRACIA;;
221) ssh ESP_ASR901_ELTUMA;;
222) telnet ESP_ASR901_NANDAIME;;
223) ssh ESP_ASR901_IBW;;
224) ssh ESP_ASR901_INCAE2;;
225) ssh ESP_ASR901_TICOMO;;
226) ssh ESP_ASR901_ENTRADA_TICUANTEPE;;
# SW 228
250) telnet ESP_SWEL228_VERACRUZ;;
251) telnet ESP_SWEL228_VILLA_FONTANA;;
253) ssh ESP_SWSF302_UCA2;;
254) ssh ESP_SWSF302_ROT_GUEGUENSE;;
255) ssh ESP_SWSF320_PLAYA_ROSADA;;
256) telnet ESP_SWES228_CHIQUILISTAGUA;;
257) telnet ESP_SWES228_MASAYA_CENTRO;;
258) ssh ESP_SWSF302_RPTO;;
259) ssh ESP_SWSF300_SANJUDAS;;
260) ssh ESP_SWSF302_SANJUDAS3;;
261) ssh ESP_SWSF302_CRTRA_TICUANTEPE;;
262) ssh ESP_SWSF302_GRANADA_01;;
263) ssh ESP_SWSF302_VERACRUZ3;;
264) telnet ESP_SWES228_ROBERTO_TERAN;;
265) telnet ESP_EL228_DISCOVERY;;
266) ssh ESP_SWSF302_CIUDAD_DARIO;;
267) ssh ESP_SWSF302_SAPOA;;
268) ssh ESP_SWSF302_ACOYAPA;;
269) ssh ESP_SWSF302_MALPAISILLO;;
270) ssh ESP_SWSF302_SIUNA;;
271) ssh ESP_SWSF302_LOSLLANOS;;
272) ssh ESP_SWSF302_PLAYA_EL_COCO;;
273) ssh ESP_SWSF302_PUERTOSANDINO;;
274) ssh ESP_SWSF302_SANIGNACIOCONCEPCION;;
275) ssh ESP_SWSF302_CUAPA;;
276) ssh ESP_SWSF302_CARDENAS;;
277) ssh ESP_SWSF302_RANCHOGRANDE;;
278) ssh ESP_SWSF302_WIWILINUEVASEGOVIA;;
279) ssh ESP_SWSF302_SALINASGRANDES;;
280) ssh ESP_SWSF302_BOACOVIEJO;;
281) ssh ESP_SWSF302_ESTPOLGRA;;
282) ssh ESP_SWSF302_RAJUENSE;;
283) ssh ESP_SWSF302_ELCOMEJEN;;
284) ssh ESP_SWSF302_JIQUILILLO;;
285) ssh ESP_SWIE3010_GRANADA_02;;
286) ssh ESP_SWSF302_PUNTATEONOSTE;;
287) ssh ESP_SWSF302_SANJOSECUSMAPA;;
288) ssh ESP_SWSF302_POLARIS;;
289) ssh ESP_SWSF302_LASTORRES;;
290) ssh ESP_SWSF302_CERROLARGO ;;
291) ssh ESP_SWSF302_ALMENDRO;;
292) ssh ESP_SWF302_TICUANTEPE;;
# SW IE3010
300) ssh ESP_SWIE3010_EL_VIEJO;;
301) ssh ESP_SWIE3010_TIPITAPA4;;
302) ssh ESP_SWIE3010_LOS_VALCANES;;
303) ssh ESP_SWIE3010_ABERDEEN;;
304) ssh ESP_SWIE3010_SBENITO;;
305) ssh ESP_SWIE3010_MBONILLA;;
306) ssh ESP_SWIE3010_TIPITAPA8;;
308) ssh ESP_SWIE3010_MATAGALPA;;
309) ssh ESP_SWIE3010_PACAYA;;
310) ssh ESP_SWIE3010_JINOTEPE;;
311) ssh ESP_SWIE3010_LALIMA;;
312) ssh ESP_SWIE3010_ELTUMA;;
313) ssh ESP_SWIE3010_VILLAFLOR;;
314) ssh ESP_SWIE3010_MASAYA_CENTRO;;
315) ssh ESP_SWIE3010_MONTEFRESCO;;
#
400) telnet FWSM1;;
401) telnet FWSM2;;
402) ssh ESP_CAT3550_COFRADIA;;
#
500) ssh ESP_MX960_MTSO;;
#
0) exit;;
*) echo "Opps!!! Please select a valid choice ";
echo "Press a key. . ." ; read ;;
esac
done
\$\endgroup\$
2
\$\begingroup\$

It's a pity to enter all those server names manually, twice: once for the choice number listing, and one more time for the ssh / telnet command selection.

A better way would have been to create a file with the list of the command-servername pairs, like this:

ssh ESP_R7609S_MTSO
ssh ESP_R7609_RIGUERO
telnet ESP_R7609_SUBASTA
ssh ESP_R7606_BOLONIA
ssh ESP_R7609_LINDAVISTA
ssh ESP_R7609_UCA

Let's call this info.txt.

Then, the script could read this file into a Bash array:

info=($(cat info.txt))

The list of choices can be printed with this loop:

print_choices() {
    for ((i = 0; i < ${#info[@]}; i += 2)); do
        j=$((i + 1))
        choice=$((i / 2 + 1))
        printf "$green%s$endColor\n" "$choice: ${info[j]}"
    done
}

Note that the choice numbers are different from your original, because I see that some numbers were (inexplicably) skipped. In this version the listing is programmatic, so it's orderly, from 1 to 235.

You could use this function to print the list of choices to the user, and grep on its output to filter, just like in the original script.

When the user makes a choice, you could calculate the correct position in the Bash array by applying the reverse logic that I used above in the print_choices function (I leave that as an exercise for you).

A note about bad practices

When a simple echo is not enough, you need to use any of its flags, it's better to use printf instead, as it's more portable.

A better way to put a large string into a variable:

read -d '' LISTA << EOF
${bred}+----------------------------------------------------------------+${endColor}
${green}[1] ESP_R7609_MTSO${endColor}
${green}[2] ESP_R7609_RIGUERO${endColor}
${green}[3] ESP_R7609_SUBASTA${endColor}
${green}[4] ESP_R7606_BOLONIA${endColor}
EOF

Notice that with this way you don't need to put the \n line ending characters.

However, it's often a code smell to have large texts in variables. It's better to put the large text into a separate file, as I demonstrated above.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.