Last active
February 17, 2022 18:40
-
-
Save sharanpeetani/3716510f5527102f594819111c092c62 to your computer and use it in GitHub Desktop.
script to check ssh connection and uptime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
USR='username' | |
for host in $(cat host_list) | |
do | |
sshpass -f pd_file ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=5 ${USR}@${host} exit | |
let ret_code=$? | |
if [ $ret_code -eq 5 ]; then | |
echo "${i} Connection Refused!" $ret_code | |
elif [ $ret_code -eq 255 ]; then | |
echo "${i} server down!" $ret_code | |
elif [ $ret_code -eq 0 ]; then | |
echo "${i} is up and Connected!" $ret_code | |
echo "uptime: `uptime | awk -F'( |,|:)+' '{ | |
d=h=m=0; | |
if ($7=="min") | |
m=$6; | |
else { | |
if ($7~/^day/) { d=$6; h=$8; m=$9} | |
else {h=$6;m=$7} | |
} | |
} | |
{ | |
print d+0,"days,",h+0,"hours,",m+0,"minutes." | |
}'`" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment