Error running grep on Remote Servers

Im running the below command

sshpass -p mypassword ssh -t user1@server2 /bin/bash -c 'echo "mypassword" | sudo -S -l; echo "$?#`grep -iE "user66|dbuser|tomcat|splunk|stash|jira|user2|docadmin" /etc/passwd`"; exit'

Below is the error I get: Output:

I run this command across a set of 500+ servers.

I also tried using egrep but it still did not work.

Note: Strangely grep -iE "user66|dbuser|tomcat|splunk|stash|jira|user2|docadmin" /etc/passwd works fine with ksh shell when i manually fire it from the remote server2

I m looking for a solution by which I could enforce to either use bash shell on remote servers or have a grep / egrep / fgrep / ggrep or by specifying complete path to a particular grep command that works across different flavors or unix Linux servers.

Sigh, here we go again: have you actually read what i wrote in response to your problem yesterday? Now you cram (again) fifteen commands into one commandline and wonder why you get confused - honestly, i would get confused too and i think i know a bit or two about shell programming.

Actually, strangely, you explicitly fire up a bash , which is not a ksh and that two different shells behave differently sometimes is not "strange", it is no wonder.

Second, you seem to think that quotations can be nested:

 /bin/bash -c '... "..." | ... ; ... "...`... "..." ...`"; ...'

Inside a single-quoted string a double-quote character is just a normal character (besides: and vice versa). That is:

"    '      "     and     '    "     '

are just two quoted strings, a double-quoted one and a single-quoted one. The single-quotes in the first and the double-quotes in the second are just one more character.

Third, you have now read probably a hundred times that YOU SHOULD NOT USE BACKTICKS! How often does someone have to point that out to you until you realize that some of us actually know what we are talking about? It is utterly frustrating to solve the same problem over and over again for you because nothing anybody here is telling you seems to have any lasting effect. By the way: also the backticks are just simple characters with no meaning at all inside a single-quoted string. Try this on the commandline:

echo '`date`'

and you will see a simple string `date` in the output, not the date itself.

Alas, i suppose you will ignore what i write again, so i spare you (and me) advice on how to do better what you want to do. You won't heed my advice anyway.

bakunin