Skip to content

Commit fdce7a4

Browse files
authored
Update ssh-manager.sh
1 parent 6c634fb commit fdce7a4

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed

ssh-manager.sh

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fi
148148

149149

150150

151-
}
151+
}
152152

153153
editServerUser(){
154154

@@ -162,7 +162,7 @@ editServerUser(){
162162
user=$newUser
163163
fi
164164

165-
}
165+
}
166166
addNewServerPassword(){
167167

168168

@@ -190,7 +190,7 @@ editServerPassword(){
190190
user=$newPassword
191191
fi
192192

193-
}
193+
}
194194

195195

196196
addNewServerKeyFile(){
@@ -228,7 +228,7 @@ editServerKeyFile(){
228228
fi
229229
fi
230230

231-
}
231+
}
232232

233233
addNewServerOption(){
234234
read -p "Enter the options leave blank if not used: " option
@@ -239,7 +239,7 @@ editServerOption(){
239239

240240
printf "Current option is %s \n " "$option"
241241
read -p "Enter the path to the key file or leave blank to use current option: " newOption
242-
}
242+
}
243243

244244

245245
createNewSSHCredentials(){
@@ -268,7 +268,7 @@ createNewSSHCredentials(){
268268

269269
menu
270270

271-
}
271+
}
272272

273273
editSSHConnection(){
274274

@@ -322,7 +322,7 @@ createNewSSHCredentials(){
322322

323323

324324

325-
}
325+
}
326326

327327
listSSHCredentials(){
328328
fileEmptyCheck
@@ -336,7 +336,41 @@ listSSHCredentials(){
336336

337337
menu
338338

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+
}
340374

341375
connectToSSHServer(){
342376

@@ -413,7 +447,7 @@ fi
413447

414448

415449

416-
}
450+
}
417451

418452
deleteSSHServer(){
419453

@@ -459,7 +493,7 @@ fi
459493
listSSHCredentials
460494

461495

462-
}
496+
}
463497

464498
menu(){
465499

@@ -468,20 +502,22 @@ fi
468502
printf "%s${info}===========================${reset}\n"
469503
printf "1. List Saved SSH connections \n"
470504
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] : "
476511
read -p "" choice
477512

478513
case $choice in
479514
1) listSSHCredentials;;
480515
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;;
485521
*) printf "%s${warning}Invalid choice${reset}\n"; menu;;
486522
esac
487523

0 commit comments

Comments
 (0)