LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2007, 11:52 AM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,189

Rep: Reputation: 60
Expect Utility and Telnet


Can anyone tell me how I can simply using expect, telnet to a host, get the login prompt, end the telnet session right there and then send the results to variable.

PHP Code:
 telnet 192.168.1.2 
Trying 192.168.1.2
... 
Connected to 192.168.1.2
Escape character is '^]'
login
telnetquit 
Connection to 192.168.1.2 closed

but instead:

PHP Code:

# in the script.  # Open a telnet session to a remote server, and wait for a prompt.

  
spawn telnet $remote_server
  expect 
"login:"
# Exit the telnet session.
  
send "exit\r"
  

# Capture the results of the command into a variable. This can be displayed, or written to disk.

set results $expect_out(buffer
Thanks

Last edited by metallica1973; 12-28-2007 at 12:03 PM.
 
Old 12-28-2007, 02:58 PM   #2
unreal128
Member
 
Registered: Jun 2003
Distribution: SuSE, Slackware, Gentoo
Posts: 207

Rep: Reputation: 30
Your script looks good but you just need to send "^]\rquit\r" instead of exit.
 
  


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
Can't end telnet servcie in xinetd when close remote telnet cliend forcefully. zeroneworld Linux - General 1 12-06-2007 08:17 AM
Expect Utility newbie Queenie245 Programming 2 10-12-2007 11:07 AM
tcl/expect telnet spawns randomly close Hewson Programming 1 05-12-2007 11:25 AM
telnet server not reliable for expect script powah Linux - Software 0 11-16-2005 12:07 PM
Automae telnet log in and execute commands (expect and send) rajatgarg Linux - Networking 0 06-24-2004 12:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:24 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
Open Source Consulting | Domain Registration