Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


ksh question: Is there such a thing as a remote grep

Posted on 2004-11-18
Medium Priority
Last Modified: 2013-12-26

I have a situation where I am running a ksh script on serverA.  I would like to search for a string in a file that resides on serverB.
I know exactly where the file is located in serverB.  Copying the file from serverB to serverA is NOT an options. How can I execute a grep on serverA and look for a string in a file located on serverB ?
Question by:jmohsin
  • 2
  • 2
LVL 13

Assisted Solution

gripe earned 1000 total points
ID: 12616844
There's a few ways you could do this. You could set up an NFS server on ServerB and remotely mount the directory containing the files you want to search on ServerA.

You could also use ssh or rsh to execute the command remotely (and return the output locally) like this:

ssh -l username ServerB 'grep foobar /path/to/file'

Author Comment

ID: 12617357
ssh look good; however, how do I pass in the password ?  On the command line, it prompts me for the password.  How can I provide the password if I use ssh in a script ? I do have full credentials for ServerB.
LVL 14

Accepted Solution

chris_calabrese earned 1000 total points
ID: 12617737
SSH supports not only passwords, but also encryption keys.

Create a key-pair on the client using ssh-keygen and copy the public part to $HOME/.ssh/authorized_keys no the server.

See the local man pages for details.
LVL 13

Expert Comment

ID: 12618205
argh.. got to it before i could. :)
LVL 14

Expert Comment

ID: 12618379
Quit griping (sorry, couldn't resist ;-)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question