MySQL Database Login SSH Servers


#!/bin/bash

hostname=${1:?”host name?”}
regexp=”(.):(.):(.*)”

Set the sshdb Data to be default if the Database is UNSpecified
default_sshdb=”/home/jing/sshserver/sshdb”
sshdb=${2:-$default_sshdb}

Read the Host to be Connected
account=$(awk -v host=$hostname ‘
/^[^#].*/ {
if ( $1 ~ host ) {
printf $2 “:”$3 “:”$4
exit
}
}
‘ $sshdb)
if [[ $account =~ $regexp ]];then
ip=${BASH_REMATCH[1]}
username=${BASH_REMATCH[2]}
password=${BASH_REMATCH[3]}
fi

Make the Connection
/usr/bin/expect -f /home/jing/sshserver/expectedssh $username $ip $password

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s