I am trying to automate a SSH bash script to check whether my server is able to SSH the remote devices. I can not install any third party tool like sshpass, expact or Net:SSH as it is not allowed in my organization.
I have created an ip.txt file which contains the IP addresses. Script will pick the first IP and SSH the device. In next step I want to supply any command say date and last exit. Everything goes well until I supply exit command. "Exit" command terminates the whole script instead going to the next loop/IP.
Is there any way to continue the script even after supplying the exit command on the remote device prompt?
However, the below commands works: ssh username$IP "date && exit" but I have different commands to run on different servers.
Code it working fine but when exit command is supplied, shell script gets terminated.
#!/bin/bash
for IP in `cat /home/ip.txt`
do
echo "Going to SSH first $IP"
ssh username@$IP
date >> log.txt
exit >> log.txt
echo "Completed first loop for $IP"
done
I want to enter the commands manually and want the script should not terminate when exit command is supplied.