I am writing a bash script that goes through a number of hosts defined in hosts.list and returns if they are online. I would like to do the same but with ssh. How to I return a value from ssh like boolean if the connection and login was successful.
#!/bin/bash
File="hosts.list"
Hosts=$(cat $File)
declare -i deadhosts
$deadhosts = 0
declare -i counter
$counter = 0
for Host in $Hosts
do
if ! ping -c 1 -s 1 -W 1 "$Host" 1>/dev/null 2>&1; then
deadhosts=$((deadhosts+1))
else
echo $Host
fi
counter=$((counter+1))
done
echo "Mission success"
echo "Scanned Hosts: $counter Dead Hosts: $deadhosts"