1

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.

Crowor
  • 123
  • 2
  • 13

1 Answers1

1

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.

Khaled
  • 36,533
  • 8
  • 72
  • 99
  • OMG, not every hero wears a cape. I am very grateful, thank you. – Crowor Jun 22 '17 at 09:51
  • BTW, while you cannot put spaces around the `=` in an assignment, you *must* use them in a comparison (e.g. `if [ $a=$b ]` does not do what you think it does). Also, there are a number of other problems with your script, such as variable references that aren't wrapped in double-quotes. [shellcheck.net](http://www.shellcheck.net) will point out many of them. – Gordon Davisson Jun 23 '17 at 01:06