Home > Blockchain >  conditional binary operator expected with Do and ssh connection
conditional binary operator expected with Do and ssh connection

Time:05-10

This is part of my code that I working to find a word in a remote server connecting via ssh to that server

filename=test.repo
word=fail
exists=$(grep -c $word $filename)
file_server=$1

for i in $(cat $file_server)
    do echo ''; echo $1 ;
    ssh $i "printf '\e[33m'; hostname; printf '\e[0m\n]' ;
    cd /etc/yum.repos.d/;
    grep -c $word $filename;
    echo $exists;
    if [[ $exists -gt 0 ]];
        then printf 'Keyword found, cleanup starts \n';
            else printf ''$word', was not found, nothing to do here with '$filename'. \n';
fi"

done

This works with just the Do command, but if I add the if [[$exist -gt 0]]; , this got an error

bash: -c: line 4: conditional binary operator expected bash: -c: line 4: syntax error near ;' bash: -c: line 4: if [[ -gt 0]]; '

any suggestion

CodePudding user response:

This line should be cut from the beginning of the script: exists=$(grep -c $word $filename)

And replace the call to grep inside the loop.

  • Related