Ssh – Bash – Insert variables into string (command not found)

bashshellssh

I try to write a script for get some software's version from many servers.
But I get this error message, when i try.

bash: Postfix verzio: MariaDB verzio: OS verzio: Java verzio: :
command not found

bash: postfixverzio: command not found

Null message body; hope that's ok

#!/usr/bin/env bash

parancsok=$(<verziok_lekerdezese.sh)

while read line
do
    array=($line)
    echo "IP Addresses : ${array[0]} "
    ssh -t -t root@${array[0]} ${parancsok}
done < ipcimek_test.txt

Verziok_lekerdezese.sh:

postfixvr = $(postconf -d | grep -m 1 mail_version | cut -d= -f2)
mariadbvr = $(mysql -v)
osvr = $(cat /etc/redhat-release)
javavr = $(java -version)
hostname = $(cat /etc/hostname)

body = "Postfix verzio: $postfixvr MariaDB verzio: $mariadbvr OS verzio: $osvr Java verzio: $javavr"

echo $body | mail -s "Verziok - Szervernev: $hostname" sample@sample.com

exit

I apologize for my bad english.

Best Answer

You need to remove the spaces on both sides of equal char = (in the assignment statements) in your bash script. So, the lines:

postfixvr = $(postconf -d | grep -m 1 mail_version | cut -d= -f2)
mariadbvr = $(mysql -v)
osvr = $(cat /etc/redhat-release)
javavr = $(java -version)
hostname = $(cat /etc/hostname)

should be written as:

postfixvr=$(postconf -d | grep -m 1 mail_version | cut -d= -f2)
mariadbvr=$(mysql -v)
osvr=$(cat /etc/redhat-release)
javavr=$(java -version)
hostname=$(cat /etc/hostname)

This applies to all assignments including body = also.

Related Topic