148
148
149
149
150
150
151
- }
151
+ }
152
152
153
153
editServerUser (){
154
154
@@ -162,7 +162,7 @@ editServerUser(){
162
162
user=$newUser
163
163
fi
164
164
165
- }
165
+ }
166
166
addNewServerPassword (){
167
167
168
168
@@ -190,7 +190,7 @@ editServerPassword(){
190
190
user=$newPassword
191
191
fi
192
192
193
- }
193
+ }
194
194
195
195
196
196
addNewServerKeyFile (){
@@ -228,7 +228,7 @@ editServerKeyFile(){
228
228
fi
229
229
fi
230
230
231
- }
231
+ }
232
232
233
233
addNewServerOption (){
234
234
read -p " Enter the options leave blank if not used: " option
@@ -239,7 +239,7 @@ editServerOption(){
239
239
240
240
printf " Current option is %s \n " " $option "
241
241
read -p " Enter the path to the key file or leave blank to use current option: " newOption
242
- }
242
+ }
243
243
244
244
245
245
createNewSSHCredentials (){
@@ -268,7 +268,7 @@ createNewSSHCredentials(){
268
268
269
269
menu
270
270
271
- }
271
+ }
272
272
273
273
editSSHConnection (){
274
274
@@ -322,7 +322,7 @@ createNewSSHCredentials(){
322
322
323
323
324
324
325
- }
325
+ }
326
326
327
327
listSSHCredentials (){
328
328
fileEmptyCheck
@@ -336,7 +336,41 @@ listSSHCredentials(){
336
336
337
337
menu
338
338
339
- }
339
+ }
340
+
341
+ SSHSearchCredential (){
342
+ fileEmptyCheck
343
+ printf " %s${info} ===========================${reset} \n"
344
+ echo -e " ${info} Saved SSH Connections ${reset} "
345
+ printf " %s${info} ===========================${reset} \n"
346
+ connection=" $( cat $cfg_file_name | fzf) "
347
+
348
+ serverName=$( echo $connection | awk -F, ' {print $1}' )
349
+ serverIp=$( echo $connection | awk -F, ' {print $2}' )
350
+ serverPort=$( echo $connection | awk -F, ' {print $3}' )
351
+ serverUser=$( echo $connection | awk -F, ' {print $4}' )
352
+ serverPassword=$( echo $connection | awk -F, ' {print $5}' )
353
+ serverKeyFile=$( echo $connection | awk -F, ' {print $6}' )
354
+ serverOption=$( echo $connection | awk -F, ' {print $7}' )
355
+ echo " Option=$serverOption "
356
+
357
+ # echo $serverPort
358
+ # Here we go connecting to the server
359
+ printf " %s${success} Connecting to ${serverName} ...${reset} \n"
360
+ if [ -z $serverKeyFile ]
361
+ then
362
+ commande=" sshpass -p " $serverPassword " ssh -p " $serverPort " " $serverUser " " @" " $serverIp " " $serverOption " "
363
+ # echo $commande
364
+ $commande
365
+ else
366
+ commande=" sshpass -p " $serverPassword " ssh -i " $serverKeyFile " -p " $serverPort " " $serverUser " " @" " $serverIp " " $serverOption " "
367
+ # echo $commande
368
+ $commande
369
+ fi
370
+ menu
371
+
372
+
373
+ }
340
374
341
375
connectToSSHServer (){
342
376
413
447
414
448
415
449
416
- }
450
+ }
417
451
418
452
deleteSSHServer (){
419
453
459
493
listSSHCredentials
460
494
461
495
462
- }
496
+ }
463
497
464
498
menu (){
465
499
468
502
printf " %s${info} ===========================${reset} \n"
469
503
printf " 1. List Saved SSH connections \n"
470
504
printf " 2. Connect to a saved SSH connection \n"
471
- printf " 3. Add new SSH connection \n"
472
- printf " 4. Edit a saved SSH connection \n"
473
- printf " %s${warning} 5. Delete a saved SSH connection ${reset} \n"
474
- printf " 6. Exit\n"
475
- printf " Enter your choice [1-6] : "
505
+ printf " 3. Search and connect to a saved SSH connection \n"
506
+ printf " 4. Add new SSH connection \n"
507
+ printf " 5. Edit a saved SSH connection \n"
508
+ printf " %s${warning} 6. Delete a saved SSH connection ${reset} \n"
509
+ printf " 7. Exit\n"
510
+ printf " Enter your choice [1-7] : "
476
511
read -p " " choice
477
512
478
513
case $choice in
479
514
1) listSSHCredentials;;
480
515
2) connectToSSHServer;;
481
- 3) createNewSSHCredentials;;
482
- 4) editSSHConnection;;
483
- 5) deleteSSHServer;;
484
- 6) exit ;;
516
+ 3) SSHSearchCredential;;
517
+ 4) createNewSSHCredentials;;
518
+ 5) editSSHConnection;;
519
+ 6) deleteSSHServer;;
520
+ 7) exit ;;
485
521
* ) printf " %s${warning} Invalid choice${reset} \n" ; menu;;
486
522
esac
487
523
0 commit comments