Commit c8db23a9 by Rinat K. Nugaev

Added automatic adding username after first successuf login

parent 63c5bc23
...@@ -5,14 +5,15 @@ ...@@ -5,14 +5,15 @@
# EDITED : 19-07-2017 # EDITED : 19-07-2017
# COMMENT : This script creates tunnels for Unicredit servers in DMZ # COMMENT : This script creates tunnels for Unicredit servers in DMZ
# Use it for your own risk! # Use it for your own risk!
# VERSION : 1.3 # VERSION : 2.1
########################################################### ###########################################################
# #
#CHANGELOG #CHANGELOG
# Version 1.0: 19-07-2017 - Changed the code # Version 1.0: 19-07-2017 - Changed the code
# - Added better variables checking # - Added better variables checking
# - Changed users's array creating # - Changed users's array creating
# - Function added # - Function added
# - Added automatic adding username after first successuf login
user="" user=""
#Defining some colours for fun ))) #Defining some colours for fun )))
RED='\033[0;31m' RED='\033[0;31m'
...@@ -24,21 +25,18 @@ eval `ssh-agent -s` ...@@ -24,21 +25,18 @@ eval `ssh-agent -s`
ssh-add ssh-add
#Ask user for username #Ask user for username
if [ -z "$user"] ; then if [ -z "$user" ] ; then
echo "Username not defined in script, asking for username!" echo "Username not defined in script, asking for username!"
read -p "Enter your username like PertrovPP:" user read -p "Enter your username like PertrovPP:" user
else statusssh=$(ssh -o BatchMode=yes -o ConnectTimeout=5 -p 10022 $user@tunnel01.rbtechnologies.ru echo ok 2>&1)
echo "Username defined! Trying to connect..." if [[ $statusssh == ok ]] ; then
fi echo "Adding username $user for future use in script"
sed -i -e '0,/user=""/s/user=""/user='$user'/' $0
#Cheking username for ssh connection and if good then add it to script variables else
statusssh=$(ssh -o BatchMode=yes -o ConnectTimeout=5 -p 10022 $user@tunnel01.rbtechnologies.ru echo ok 2>&1) echo "Username defined! Trying to connect..."
if [[ $statusssh == ok ]] ; then fi
echo "Adding username $user for future use in script"
sed -i -e 's/user=nrk/user='$user'/g' $0
else
echo other_error
fi fi
#Cheking username for ssh connection and if good then add it to script variables
...@@ -63,6 +61,3 @@ fi ...@@ -63,6 +61,3 @@ fi
done done
exit 0 exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment