0

I am having problems with my script. When I run the script, it works. But it connects to a single server. "iplist.txt" is connecting to the first IP address field. It is not connected to other servers. I do not know where I'm doing wrong. Can you help me ?

I have studied and applied many questions that have been asked before. But the result is the same again.

I want to use this script for different purposes in the future. I have a 140 linux servers and have zabbix agent. But zabbix agents on the servers are out of date.

My Script;

#!/bin/bash
#set -x

servers=/Users/spala/works/iplist.txt

#set -u

while read -u140 multiplessh;
do


USER="testuser"
PASS="testpassword"
PORT="55022"
current_ver="3.2.3"

command1="/usr/sbin/zabbix_agentd -V & hostname -f /dev/null"
connection_method=`/usr/local/bin/sshpass -p $PASS /usr/bin/ssh -n -p$port -o StrictHostKeyChecking=no $user@$multiplessh $command1`


first_step="$connection_method"

###
result=$(echo $first_step |grep 'zabbix_agentd\|.spala' | awk '{print $1, $5}')
# - 'zabbix_agentd' ---> "zabbix_agent -V" command output..
# - '.spala' my server hostname fqdn..--> test.spala test1.spala test2.spala

hostname=$(echo $result |awk '{print $1}')
version=$(echo $result |awk '{print $2}')


if [[ "$version" == "$current_ver" ]]
then
   echo "$hostname used version ---> $version"
   echo "Version is ok..."
   exit 1
else
   echo "$hostname used version ---> $version"
   echo "Old version.. Need update !"
   exit 1
fi
exit 0

done 140<"$servers"

script results;

sh test.sh
test1.spala used version ---> 3.2.2
Old version.. Need update !

my iplist file;

cat /Users/spala/works/iplist.txt
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
5.5.5.5
...
total 140 servers
0

Notice the exit 1 and exit 0 lines in your script? They explicitly stop the script. You probably copied this from somewhere else that was intended to be run as a standalone file, but in your case it just means that the script will exit after connecting to the first IP.

Granted, this isn't how you should be aiming to do this.

  • do not use sshpass for daily operations. Use it once to set up key authentication
  • consider using system management tools like Puppet, Chef and many, many others
  • consider using proper packages, then you can use the package management tools to verify the version. Also, use package repositories for easy upgrade management
  • Removed the exit parameter to fix it. Thanks. – spala Dec 28 '16 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.