LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 03-02-2012, 12:50 AM   #1
anirudha0012
LQ Newbie
 
Registered: May 2009
Posts: 14

Rep: Reputation: 2
Question 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.
 
Old 03-02-2012, 01:11 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Have you tried the 'tee' cmd http://linux.die.net/man/1/tee
http://linux.101hacks.com/unix/tee-command-examples/
 
1 members found this post helpful.
Old 03-02-2012, 01:16 AM   #3
anirudha0012
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 2
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to capture Net::FTP session log to a file ? aullah Linux - Newbie 1 04-21-2011 01:36 PM
[SOLVED] Redirecting console output from a Qt application to a telnet session bameije Linux - Embedded & Single-board computer 4 01-21-2011 10:32 AM
get output from telnet session? Manana Linux - Networking 4 01-24-2007 03:20 AM
How to log command output from telnet session even after logout from the remote serve UltraSoul Solaris / OpenSolaris 2 10-15-2006 09:20 PM
Pipe telnet session output to text file joshlamerritt Linux - Software 3 02-10-2004 09:42 PM


All times are GMT -5. The time now is 12:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration