Error running grep on Remote Servers

Trivia Category: Science: Mathematics
Difficulty: Easy
A universal set, or a set that contains all sets, exists.
True or False?
Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
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:

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.

Last edited by mohtashims; 01-18-2019 at 11:42 AM..
# 2  
Originally Posted by mohtashims
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 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.

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running set of commands in remote servers in shell script

Hi Wishing to all. I am very new joined in an organization as a unix system administrator. I need a help in preparing a script for a report. i have a file contains all of the linux/ubuntu servers line by line around 140 servers. vi servers.txt nh01 nh02 nh03 bh01 bh04 - - :wq (3 Replies)
Discussion started by: kumaraswamy
3 Replies

2. Shell Programming and Scripting

Remote login and running a script on multiple servers

Hi all, I am baffled on this. Solaris Irix system.:confused: I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek: ... (10 Replies)
Discussion started by: weddy
10 Replies

3. UNIX for Dummies Questions & Answers

Help with Copying files between two remote servers

Hi All, Please help me for a shell. I am a New to unix I am trying to DB dump file from one server and copying it to another server. From My Local ServerA connecting to remote ServerB using ssh and taking dump of a instance. That Dump file i need to copy to ServerC. I am able to connect... (6 Replies)
Discussion started by: maddyd2k
6 Replies

4. Shell Programming and Scripting

Help with script to reach remote servers

new3=`cat /tmp/list3` for pol in "$new3" $(su - dbadmin -c "ssh $new3 '/usr//llist'"); do export policy=`echo $pol`; su - dbadmin -c "ssh $x '/usr/policycmd $policy -L |grep -i active; echo $policy'">>/tmp/listxyz;done I am having trouble with this testscript as the file list3 has two names... (1 Reply)
Discussion started by: newbie2010
1 Replies

5. Shell Programming and Scripting

Checking running process status using "grep" on multiple servers in load sharing system.

Suppose i have 3 different servers say x,y and z. Im running some process say ABC and 40 instances for the same is being created. In load sharing suppose on server x, 20 instances are running server y, 10 instances are running server z, 10 instances are running. While checking the... (1 Reply)
Discussion started by: ankitknit
1 Replies

6. UNIX for Dummies Questions & Answers

Running the same remote script on multiple servers

Experts, Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file. I struggled with this yesterday & finally that script is working now. Now, here is a scope creep and the script that I wrote for 1 remote... (2 Replies)
Discussion started by: OMLEELA
2 Replies

7. UNIX for Dummies Questions & Answers

Is there a way to Grep processes running on Windows Servers...

Hi guys - newbie question: Is there a way for me to grep running processes from a windows machine? If its possible I could then try to script it. Currently I can see Windows file shares on my Linux server. (4 Replies)
Discussion started by: DallasT
4 Replies

8. Shell Programming and Scripting

Status of remote servers

hi, Say me the command to check the status of server. whether its up or down (11 Replies)
Discussion started by: satheeshkr_cse
11 Replies

9. SuSE

Amber Lights + Remote Servers

Ok, so we get reports from operations after they do walk throughs about servers with amber or red lights showing. They want us to resolve the issues. On Solaris I can run prtdiag to identify the amber lights and clear them (replace hardware or "reboot" the daemon). How do I remotely figure out... (1 Reply)
Discussion started by: BOFH
1 Replies

10. Shell Programming and Scripting

Connecting to remote servers

Please advise, The previous thread asked about the automated transfer of files between two servers. The question is - is there any way of encrypting the password within the script or is it a matter of setting the permissions settings on the script so that it can only be executed and possibly... (1 Reply)
Discussion started by: rdbooth
1 Replies

Featured Tech Videos