LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 07-27-2013, 10:16 AM   #1
snjksh
Member
 
Registered: Jan 2008
Location: Pune, India
Distribution: RHEL
Posts: 34

Rep: Reputation: 0
expect script for telnet not working


Hi,

Please refer the expect script.

Code:
#!/usr/bin/expect
set timeout 20
set ip [lindex $argv 0]
set port [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]
spawn telnet $ip $port
expect "'^]'." sleep .1;
send "\r";
sleep .1;
expect   "login:"
send "$user\r"
expect "Password:"
send "$password\r";
interact
Getting error while running below command

Code:
#./telnet.sh 192.168.1.10 23 bob redhat
spawn telnet 192.168.1.10 23
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
must have one arg: seconds
while executing
"sleep"
invoked from within
"expect "'^]'." sleep .1"
(file "./telnet.sh" line 8)
 
Old 07-27-2013, 10:30 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by suma5550 View Post
Hi,
Please refer the expect script.
Code:
#!/usr/bin/expect
set timeout 20
set ip [lindex $argv 0]
set port [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]
spawn telnet $ip $port
expect "'^]'." sleep .1;
send "\r";
sleep .1;
expect   "login:"
send "$user\r"
expect "Password:"
send "$password\r";
interact
Getting error while running below command
Code:
#./telnet.sh 192.168.1.10 23 bob redhat
spawn telnet 192.168.1.10 23
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
must have one arg: seconds
while executing
"sleep"
invoked from within
"expect "'^]'." sleep .1"
(file "./telnet.sh" line 8)
So did you read the error, and look at line 8??

It very clearly says that the problem is with the sleep command, and that is because sleep takes an argument in seconds. You have not provided it, rather you're trying to pass it ".1" So, pass it a valid argument.
 
1 members found this post helpful.
  


Reply



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
[SOLVED] Perl/Expect script connecting to a server using telnet. kenji Programming 2 08-31-2012 02:29 AM
expect script to telnet into a router m4rtin Programming 5 08-02-2010 08:03 PM
Telnet script on Unix machine without expect cristoph_ Programming 7 12-24-2008 10:23 AM
Expect Scripting:- script not coming out of telnet session. nik1984 Programming 2 09-11-2008 08:14 AM
telnet server not reliable for expect script powah Linux - Software 0 11-16-2005 11:07 AM

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

All times are GMT -5. The time now is 11:10 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