# Error running grep on Remote Servers

**URL:** <https://community.unix.com/t/error-running-grep-on-remote-servers/374596>\
**Category:** Shell Programming and Scripting\
**Created:** [January 18, 2019, 7:42am UTC](https://community.unix.com/t/error-running-grep-on-remote-servers/374596 "2019-01-18T07:42:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [January 18, 2019, 7:42am UTC](https://community.unix.com/t/error-running-grep-on-remote-servers/374596/1 "2019-01-18T07:42:59Z")

</div>

Im running the below command

```plaintext
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:

> [@](#):
>
> User user1 may run the following commands on server2:  
> (ALL) ALL, !/bin/su  
> ksh: user66: not found  
> ksh: dbuser: not found  
> ksh: tomcat: not found  
> ksh: splunk: not found  
> ksh: stash: not found  
> ksh: jira: not found  
> ksh: ^J: not found [No such file or directory]  
> ksh: docadmin /etc/passwd: not found [No such file or directory]

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.

---

<div class="post-metadata">

**Author:** ![bakunin](https://community.unix.com/letter_avatar/bakunin/32/6_449c533f586939b6e5f246632a46421f.png) [@bakunin](https://community.unix.com/u/bakunin)\
**Post date:** [January 18, 2019, 3:39pm UTC](https://community.unix.com/t/error-running-grep-on-remote-servers/374596/2 "2019-01-18T15:39:23Z")

</div>

> [@mohtashims](#):
>
> ```plaintext
> 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'
> 
> ```
> 
> 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

Sigh, here we go again: have you actually read what i wrote in [response to your problem](https://www.unix.com/shell-programming-and-scripting/280800-ssh-freezes-when-run-using-different-user-id.html) 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:

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

```

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

```plaintext
" ' " 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:

```plaintext
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
