Hello Folks,
Good day,
I have a little script here where i connect to my servers using below.
# s <hostname>
Below is the sample script i had written to simplify this step successfully.
jump1 ~ $ s abc
Last login: Wed Oct 25 11:23:28 2017 from jump1
[root@abc ~]#
However i did not get the expected output as below when the script cannot find the hostname with both .XX.com and XXX.com.
echo "Could not resolved $server, please check hostname"
Can you assist to check what went wrong here?
Thank you so much.
#!/bin/bash
#
hostname=$1
server=`echo $hostname | tr '[A-Z]' '[a-z]'`
ping -q -c 1 $server.XX.com &>/dev/null
if [ "$?" = 0 ];
then
ssh -q -o StrictHostKeyChecking=no -l root $server.XX.com
else
if [ "$?" -ne "0" ];
then
ssh -q -o StrictHostKeyChecking=no -l root $server.XXX.com
else
echo "Could not resolved $server, please check hostname"
fi
fi