Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to know how to grab output and store it in a variable. I don't want to send all the output to the file, just one of the commands output I am sending.. Basically

AUTH
AUTH
LIST  <---needs to go to file

I tried.. read $response but it isn't working.

share|improve this question
    
Out of many output which one in specific you want to store. Only LIST for one time purpose or you want a script of it. – Vineet Sharma Mar 13 at 18:21

You have to eliminate $:

read response
share|improve this answer

nc isn't expect, so you have no control over which parts of the remote host's output are captured. You can redirect the entire output to a file (and process the file later with awk, sed, perl, or whatever to extract only what you need) or pipe it directly into awk (or whatever) before writing to a file or storing it in a shell variable (with $() command substitution).

However, you'd almost certainly be better off writing your script in perl (and use either the Expect.pm module or Net::Telnet, or Net::IMAP) or in python using pexpect (or python's imaplib2 library), or in some other language with an expect-like library or IMAP client library.

That would allow you to connect to the relevant port (IMAP, by the look of it) on the remote host, issue whatever commands you need, wait for responses, and do whatever you need with the response (including saving some of the responses to a file)

I've added the /expect tag to your question - click on it to get a list of expect-related questions and answers on this site.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.