Running test command in ssh

I tried to run the following commands in my shell script.

This command works fine for me:

ssh -n "${username}"@"${hostname}" "grep WARNING ${serverhome}/${serverlog} | wc -l"

The result is:
1548

However when i try to run a similar one:

ssh -n "${username}"@"${hostname}" "test `grep -q WARNING ${serverhome}/${serverlog}` && echo warning || echo good"

I get:

grep: /home/test-user/server/server.*.log: No such file or directory

I suspect i did not use the proper quote characters in the second command. But i don't know how to fix it. Thanks for the help.

Hi try something like:

ssh -n "${username}@${hostname}" grep -q WARNING "${serverhome}/${serverlog}" && echo warning || echo good
1 Like

Problem revisited:
-----
The above approach would not be right since it would give the wrong result if the ssh command failed. So a better approach may be to let the other side provide the echo:

ssh -n "${username}@${hostname}" "grep -q WARNING \"${serverhome}/${serverlog}\" && echo warning || echo good"
1 Like