Wednesday, 6 December 2017

SSH script to access multiple servers


#!/bin/ksh
#set -x
LOGFILE=/tmp/scan.log
echo " Scan test` date ` " > $LOGFILE
echo " " >>$LOGFILE
echo " " >>$LOGFILE
echo "==================================================================================================================" >>$LOGFILE
for i in ` cat /tmp/server.lst` ; do
server=`echo $i | awk -F\~ ' { print $1} ' `
echo Scan Status for $server  | tee -a $LOGFILE
/usr/sbin/ping $server
var_ping=$?
if [[ $var_ping -eq 0 ]] ; then
    ssh -o batchmode=yes $server true
    var_date=$?
    if [[ $var_date -eq 0 ]] ; then
      echo $server id | tee -a $LOGFILE
      ssh $server id | tee -a $LOGFILE
      echo "==================================================================================================================" >>$LOGFILE
    else
      echo $server ========== not Accessable =========== >>$LOGFILE2
    fi
else
  echo $server ========== not pingable =========== >>$LOGFILE2
fi
done

No comments:

Post a Comment

ZFS

Public Cloud tools comparison