Grep on console output

Hellos!

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, I am not sure how to do this using telnet. ssh is an option that I can think of. Would you be able use ssh, instead?

Why telnet and not ssh? ssh is far easier to automate. You could just do ssh username@host command | grep ... and it'd do what you expect.

without ssh, you might have to bodge a monster with expect.

Damnation! I am trying to SSH into the server but the server does not accept SSH, only telnet.

I was checking online and the easier way with telnet would be: once I telnet into the server, the script should direct the console output into a file and grep that file for the info

Puneet, I seem to have more questions than answers, for you. Is rsh or rlogin an option?

Please note that ssh is a preferred way to do these things, as it is more secure. Perhaps, you can suggest it to the SA. :slight_smile:

  • GP

if you must use telnet you can automate this with the Expect language.

Good morning GP,

rsh and rlogin are both not an option for me. I talked with the Admin as you suggested. Trouble is that this is for a server which runs the power supply for a switch and only supports telnet.

Cheers,
Puneet

---------- Post updated at 12:50 PM ---------- Previous update was at 12:48 PM ----------

I did that. However, I am having trouble running an if statement with expect.
http://www.unix.com/shell-programming-scripting/165987-if-else-expect-script.html

Any thoughts?