-1

I am trying to get the release version of Red Hat and SUSE servers based on input from admin server which has passwdless authentication to all servers. I am neither getting error nor output, below is the code

version()
{
SERVERS='/HOME/servers' 
read -p $'Enter the server name:\n' server_name
EXIST=`cat $SERVERS|grep -i $server_name|wc -l`
if [ $EXIST -gt 0 ];then
RELEASE1='ssh -q -o "StrictHostKeyChecking no" "$server_name" cat /etc/issue'
COUNT1=`ssh -q -o "StrictHostKeyChecking no" "$server_name" cat /etc/issue|wc -l`
VERSION1=`ssh -q -o "StrictHostKeyChecking no" "$server_name" cat /etc/issue|awk '/Red/ && /Hat/'`
COUNT2=`ssh -q -o "StrictHostKeyChecking no" "$server_name" cat /etc/issue|awk '/Red/ && /Hat/'|wc -l`

if [[ -f $RELEASE1 && -s $RELEASE1 ]];then
    if [ $COUNT1 -gt 0 ];then
        echo -e " $RELEASE1 "
    elif [ $COUNT2 -gt 0 ];then
        echo -e " $VERSION1 "

    else
        echo "                  "
 fi

else echo " "

fi

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Tom15
  • 5

1 Answers1

2

You have two backticks on line-10. For syntax checking you can always use shellcheck

It is far preferred (readable too) to use $(...) for command substitution in lieu of the archaic back-quote form.

As an aside, rather than parsing /etc/issue and or files like /etc/redhat-release, install lsb_release to obtain release and distribution information.

JRFerguson
  • 14,740