I know there are other solution such as expect
, or Python paramiko
, but bash shell
is the only option available for now.
Out of these 3 IPs, only 172.16.1.2
has SSH server installed and they have similar password.
wolf@linux:~$ cat ip.txt
172.16.1.1
172.16.1.2
172.16.1.3
wolf@linux:~$
This is the Bash script
wolf@linux:~$ cat sshSession.sh
while read host
do
export SSH_ASKPASS='~/ePass'
setsid ssh -T user@$host
if [ $? = 0 ]; then
exit
echo "$host | SSH Authentication OK"
else
echo "$host | SSH Authentication PROBLEM"
fi
done < ip.txt
wolf@linux:~$
Output
wolf@linux:~$ ./sshSession.sh
ssh: connect to host 172.16.1.1 port 22: No route to host
172.16.1.1 | SSH Authentication PROBLEM
Welcome to Ubuntu Server
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
-bash: line 1: 172.16.1.3: command not found
172.16.1.2 | SSH Authentication PROBLEM
wolf@linux:~$
There are a few problems here.
I just want to get the authentication status only, not to log in into the server.
There is something wrong with the output
-bash: line 1: 172.16.1.3: command not found
172.16.1.2 | SSH Authentication PROBLEM
- This is the only host installed with SSH, while others not.
Desired Output
wolf@linux:~$ ./sshSession.sh
172.16.1.1 | SSH Authentication PROBLEM
172.16.1.2 | SSH Authentication OK
172.16.1.3 | SSH Authentication PROBLEM
What's wrong in the script and how to fix it?