Last active
February 15, 2018 10:51
-
-
Save jnikolak/e641da4ca3ad709c5edf235e56784ab3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: run the script like ./myssh 3 or if you want list of options ./myssh | |
# Written by Jon Nikolakakis with help from Jamie Bainbridge, Version 0.1 | |
# Change the knownUserloc entry to match your username | |
# Example: knownUserloc="/home/jnuser" | |
knownUserloc="/root" | |
HOSTFILE="$knownUserloc/.ssh/known_hosts" | |
# Change your kerberos | |
kerberosUser="yourKerbUsernameGoesHere" | |
# setup an alias for next login, upon next login you can just type m, to login to your servers | |
# Or you you can do something like m a where a is equal to the a='root@10.0.0.1' | |
if [ $(egrep -c myssh "$knownUserloc/.bashrc") != 0 ]; then | |
echo "myssh alias exits" | |
else | |
cat >> $knownUserloc/.bashrc <<EOF | |
alias m='/myssh.sh' | |
EOF | |
fi | |
declare -a arr=() | |
if [ -e "/$knownUserloc/.ssh/id_rsa" ];then | |
echo "id_rsa file exits" | |
else | |
ssh-keygen -t rsa | |
fi | |
# Add the servers you want to log into | |
a='root@10.0.0.1' | |
b='root@10.0.0.2' | |
c='root@10.0.0.3' | |
d='root@10.0.0.4' | |
e='root@10.0.0.5' | |
f='root@10.0.0.6' | |
g='root@10.0.0.7' | |
h='root@10.0.0.8' | |
i="$kerberosUser@op.example.com" | |
j="$kerberosUser@foo.example.com" | |
k="$kerberosUser@example.com" | |
myserv=($a $b $c $d $e $f $g $h $i $j $k) | |
for i in ${myserv[@]} | |
do | |
arr+=( "$(echo "$i" | cut -d @ -f 2)") | |
done | |
# This needs to be improved here here, it should first check on the $1, instead it goes through all, need to rewrite this. | |
for HOST in ${arr[@]}; do | |
if [ $(egrep -c "${HOST}" "$HOSTFILE") != 1 ]; then | |
echo "${HOST} not have ssh keys" | |
ping -W1 -c1 -q ${HOST} 2>&1 | |
if [ $? -gt 0 ];then | |
echo "host not reachable" | |
else | |
if [[ "$1" == ${HOST} ]];then | |
echo "do kerberos ssh = ${HOST}" | |
ssh-copy-id "$kerberosUser@${HOST}" | |
fi | |
if [[ "$1" -gt $1 ]];then | |
echo "do root ssh ${HOST}" | |
ssh-copy-id "${HOST}" | |
fi | |
fi | |
fi | |
done | |
case $1 in | |
1) | |
echo "This is the going into $a server" | |
ssh $a | |
;; | |
2) | |
echo "This is the going into $b server" | |
ssh $b | |
;; | |
3) | |
echo "This is the going into $c server" | |
ssh $c | |
;; | |
4) | |
echo "This is the going into $d server" | |
ssh $d | |
;; | |
5) | |
echo "This is the going into $e server" | |
ssh $e | |
;; | |
6) | |
echo "This is the going into $f server" | |
ssh $f | |
;; | |
7) | |
echo "This is the going into $g server" | |
ssh $g | |
;; | |
8) | |
echo "This is the going into $h server" | |
ssh $h | |
;; | |
9) | |
echo "This is the going into $i server" | |
ssh $i | |
;; | |
10) | |
echo "This is the going into $j server" | |
ssh $j | |
;; | |
11) | |
echo "This is the going into $k server" | |
ssh $k | |
;; | |
# This is executed if you didn't run it like m $1 | |
*) | |
# You can add your descriptions here | |
echo "You didn't enter a number like m 2 (or ./myssh 2) ,you can visit the following servers to get the access: " | |
echo "1) = Server #Enter Description" | |
echo "2) = Server #Enter Description" | |
echo "3) = Server #Enter Description" | |
echo "4) = Server #Enter Description" | |
echo "5) = Server #Enter Description" | |
echo "6) = Server #Enter Description" | |
echo "7) = Server #Enter Description" | |
echo "8) = Server #Enter Description" | |
echo "9) = Server #foobar" | |
echo "10) = Server #optimus" | |
echo "11) = Server #colabshell" | |
read -p "Type a number between 1 to 11: " server | |
if [ $server -eq 1 ]; then | |
ssh $a | |
elif [ $server -eq 2 ]; then | |
ssh $b | |
elif [ $server -eq 3 ]; then | |
ssh $c | |
elif [ $server -eq 4 ]; then | |
ssh $d | |
elif [ $server -eq 5 ]; then | |
ssh $e | |
elif [ $server -eq 6 ]; then | |
ssh $f | |
elif [ $server -eq 7 ]; then | |
ssh $g | |
elif [ $server -eq 8 ]; then | |
ssh $h | |
elif [ $server -eq 9 ]; then | |
ssh $i | |
elif [ $server -eq 10 ]; then | |
ssh $j | |
elif [ $server -eq 11 ]; then | |
ssh $k | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment