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

Posted on 2004-11-18
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
    LVL 13

    Assisted Solution

    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

    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

    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

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

    Expert Comment

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

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Suggested Solutions

    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
    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.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now