Unix: Grep on console output

16,291

Solution 1

Use SSH instead. It's more secure and far easier to script.

ssh remoteusername@remotehost:/path/to/remote/script | grep 'something'

with appropriate key setup, it won't even prompt you for a password.

Solution 2

Have you tried I/O redirection? You could either do

$ your-command > output.txt

and then run grep on that file, or just directly pipe the output through grep like so

$ your-command | grep ...

See this article or google around for similar. There are probably thousands of good articles about this around the web.

Solution 3

Instead of telnet, I would suggest using netcat (nc). You could then pass your login credentials via standard input and grep the standard output (nc prints anything sent by the server on standard output).

nc <host> <port> <auth.txt | grep 'string'
Share:
16,291
Puneet Sohi PMP CCNP
Author by

Puneet Sohi PMP CCNP

Updated on June 04, 2022

Comments

  • Puneet Sohi PMP CCNP
    Puneet Sohi PMP CCNP almost 2 years

    This is my first question on stackoverflow! I want to have a unix script that will run grep on the console output. Here is what my script does: 1. Telnet into a remote server (I have done this part successfully) 2. On successful login, the remote server displays outputs information on the console. I need to run grep on that console output (need help with this)

    So, I need a script to run grep on the output appearing on the console.

    Any thoughts??

    Thanks, Puneet

  • Puneet Sohi PMP CCNP
    Puneet Sohi PMP CCNP over 12 years
    Cannot use SSH, as the remote server only supports telnet!