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