LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Capture the telnet session output in file (http://www.linuxquestions.org/questions/linux-newbie-8/capture-the-telnet-session-output-in-file-932269/)

anirudha0012 03-01-2012 11:50 PM

Capture the telnet session output in file
 
Hello folks,

I have number of ip listed in a text file and would telnet them on port 25 and exit if 220 banner if found.

I'm able to successfully run the script and get the output on tty, but I intend to capture the telnet session output in a file which i'm unable to do so either with script command or redirection.

Code:

#!/bin/bash
for ip in `cat ip.txt`
do
expect<<EOF
spawn telnet
expect "telnet>"
send "open $ip 25\n"
expect "^220"
send "quit\r"
EOF
done

and this outputs as below

Code:

# sh conn.sh
spawn telnet
telnet> open 74.125.79.27 25
Trying 74.125.79.27...
Connected to ey-in-f27.1e100.net (74.125.79.27).
Escape character is '^]'.
220 mx.google.com ESMTP z1si4136250eem.165
spawn telnet
telnet> open 74.125.113.27 25
Trying 74.125.113.27...
Connected to vw-in-f27.1e100.net (74.125.113.27).
Escape character is '^]'.
220 mx.google.com ESMTP hn4si4261830vdb.140

This output is on the screen, which i'm unable to send it to any file.

Please assist me in with this problem.

chrism01 03-02-2012 12:11 AM

Have you tried the 'tee' cmd http://linux.die.net/man/1/tee
http://linux.101hacks.com/unix/tee-command-examples/

anirudha0012 03-02-2012 12:16 AM

Thank you chrism01,

i included the expect environment and executed the script
#except conn | tee out.txt

Now i'm able to get the output for future reference

Thanks again


All times are GMT -5. The time now is 07:44 PM.