Advertisement
sanaij

ssh_test_connection_final_2

Mar 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.83 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. SERVERLIST=$1
  4.  
  5. if [[ -z $SERVERLIST ]]; then
  6.  
  7.   cat <<-End-of-message
  8.  
  9.   server list file not found ...
  10.  
  11.   usage: ./ivan.sh serverlist.txt
  12.  
  13. End-of-message
  14.  
  15. elif [[ ! -e $SERVERLIST ]]; then
  16.  
  17.   echo "File $1 does not exist. Please provide a valid server list filename"
  18.  
  19. else
  20.  
  21.   while read LINE; do
  22.    
  23.   #   for i in $(cat $SERVERLIST)
  24.  
  25.   #   do
  26.  
  27.         ping -c 1 $i  >/dev/null 2>&1
  28.  
  29.      if [ $? -ne 0 ]
  30.  
  31.       then
  32.    
  33.           echo "No response from $LINE"
  34.  
  35.       else
  36.  
  37.           ssh -q -o BatchMode=yes -o ConnectTimeout=5 $i >/dev/null 2>&1 exit
  38.  
  39.       if [ $? -ne 0 ]
  40.  
  41.       then
  42.  
  43.           echo "connection not successful in $LINE"
  44.  
  45.       else
  46.  
  47.           echo "connection successful in $LINE"
  48.    
  49.       fi
  50.      
  51.       fi
  52.      
  53.   #    done
  54.  
  55.   done < $SERVERLIST
  56. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement