21929 total geeks with 3247 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
redore
o noes the webserver was acting up earlier and it was spewing out all those full path disclosures ..
DnD
Tks, I'm checking my code.
CodeX
are you thinking of level 4? I'm sure there's been plenty of people who were dismayed after calculating the answer
MaxMouse
Also... Level5 lol, when you get the answer you'll shout at your computer, guaranteed.
MaxMouse
DnD, none of the challenges have been changed in a long time, i can assure you, none of them have a bug (Except level13, and it's more of a quirk than a bug)

Donate
Donate and help us fund new challenges
Donate!
Due Date: Feb 28
February Goal: $30.00
Gross: $0.00
Net Balance: $0.00
Left to go: $30.00
Contributors


News Feeds
The Register
Ex-Intel exec
pleads guilty to
insider trading
Adobe apologizes
for festering Flash
crash bug
Conficker outbreak
infects Leeds
hospital servers
Intel
"Tukwila" born
after long and
painful labor
SourceForge
reverses ban on US
foes
Oracle issues
emergency security
patch for WebLogic
Microsoft tests
show no Win 7
battery flaw
Microsoft kills
FAST"s Linux and
Unix search biz
Linus Torvalds
doesn"t hate the
Googlephone
Sweden to prosecute
alleged Cisco, NASA
hacker
Slashdot
Virtualizing a
Supercomputer
Study Says OOXML
Unsuitable For
Norwegian
Government
Virus-Detecting
"Lab On a Chip"
Developed At BYU
Google Shooting For
Smartphone
Universal
Translator
New Material
Transforms Car
Bodies Into
Batteries
Verizon Blocking
4chan
A Reflection On Sun
Executive Payouts
For Failure
Turns Out You
Actually Can Be
Bored To Death
Cacti 0.8 Network
Monitoring
What Are the Best
Valentine"s Day
Stunts?
Article viewer

Expect Telnet Example



Written by:dimport
Published by:dimport
Published on:2003-06-21 07:19:46
Topic:Linux
Search OSI about Linux.More articles by dimport.
 viewed 55204 times send this article printer friendly

Digg this!
    Rate this article :
Expect is a great scripting language developed by Don Libes, makes boring interaction so much easier. This is a nice telnet example, well commented.


#!/usr/bin/expect #Where the script should be run from.


set timeout 20 #If it all goes pear shaped the script will timeout after 20 seconds.

set name [lindex $argv 0] #First argument is assigned to the variable name

set user [lindex $argv 1] #Second argument is assigned to the variable user

set password [lindex $argv 2] #Third argument is assigned to the variable password


spawn telnet $name #This spawns the telnet program and connects it to the variable name


expect "login:" #The script expects login

send "$user " #The script sends the user variable

expect "Password:" #The script expects Password

send "$password " #The script sends the password variable

interact #This hands control of the keyboard over two you (Nice expect feature!)


This article was originally written by Sliptop

Did you like this article? There are hundreds more.

Comments:
Anonymous
2006-04-24 07:09:19
But while sending so I am unable to send passwords that contain @.Please guide how to send such passwors through Expect.

Anonymous
2007-01-15 20:41:23
Try using the escape character / before the @ symbol. Alternatively, put the password in quotes.
Anonymous
2007-02-20 10:07:52
You need to add \r at the end of username and password - Leela
Anonymous
2008-05-16 06:14:43
Here's a working example, which logs into the Houston server, which is running Windows 2003 Server, from a laptop running MacOS 10.5:

#!/usr/bin/expect
spawn telnet -l Administrator houston.fubar.com 2368
expect "password: "
send "a1am0\r\n"
interact

Just save into a file, chmod 700, and you're good to go.
Anonymous
2008-06-24 15:08:56
Is this an example, it made it more fuzzier to me
Anonymous
2008-08-15 21:29:54
I need to logon a legacy system ,needs a break after Escape char; so I send brk it prompts with an ? . If I put this it does not work:
expect "Escape"
send "^]\r"
send "send brk\r"
expect "?"
send "login"

and it gets stuck , any advise ?
Anonymous
2008-09-29 18:39:06
you need to "expect" after every "send". So, combine the two sends, or expect a ">" after you escape back to the telnet prompt.
Anonymous
2009-04-22 14:29:59
While sending so I am unable to send passwords that contain @.Please guide how to send such passwors through Expect. online games
Anonymous
2010-01-20 00:33:33
http://www.bagscabin.com/mulberry bags
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
bb
start svn on system boot in debian on Tue 21st Jul 10am
http://linux.justinhartman.com/Startup_S cript_for_Subversion I found this a really simple explanation of how to start svn when the server boots
bb
SSHFS: Super Easy File Access over SSH on Wed 18th Feb 1pm
This was really useful, and worked great to communicate between servers. http://www.linuxjournal.com/article/8904 Thanks to gabbs
bb
hellanzb nzb news downloader for NSLU2 on Tue 22nd May 7pm
Someone introduced me to the joyful NZB file recently. Its truly a wonderful invention, and allows my to explore usenet binary grabbing using my NSLU2. as previous nntp readers id tried made the process too painful. So simply .... 1) apt-get inst
bb
edna mp3 streaming for nslu2 on Wed 9th May 11am
I've been streaming music from my home NSLU2 server for a while now using mt-daapd (firefly) which is an ITunes server for linux. I can connect to my home network from work using ITunes and a little daap proxy app called rendevous. My friend was doing
Adnurak
How to choose the right Linux Distro on Thu 9th Nov 7pm
This is mainly for new users who want to try out Linux for the first time, but try it out if you're experienced in Linux anyway, it's kinda fun. What with all these different distributions of Linux that you hear about all the time, it's hard to choose
ketan404
my blog on Thu 9th Nov 6am
http://ketan404.blogspot.com
bb
Tweaking Apache and Mysql for Low Memory on Fri 20th Oct 11am
i implemented this to tweak my apache/mysql for better performance on my NSLU2. Hard to tell if its helping much though ;-) Mysql really doesnt run too well with apache on NSLU2 so I dont use it for much. http://www.unixshell.com/wiki/index.php/ Optimiz
Adnurak
Fate - A Linux Security Simulation Written in C++ on Fri 20th Oct 6am
Fate is a simulation of a Linux system written in C++ and meant for DOS (runs fine in winxp and winme by just doubleclicking) that according to the creator, m101, shows you the basics of security in different Linux systems, including but not limited to, M
bb
Article on building rtorrent for arm5vtel NSLU2 with debianslug on Thu 19th Oct 7am
I wrote an article today on my efforts at compiling rtorrent for debianslug. its here ... Article on building rtorrent/libtorrent for arm5vtel NSLU2 with littleendian debianslug
bb
How to mount .iso file on NSLU2 running debianslug on Tue 19th Sep 12pm
If like me your running debianslug on an NSLU2 and you'd like to mount an iso file so it can be directly streamed to Xbox Media Centre (its a beautiful solution isnt it!) then simply do the following. Ensure you have loop support in your debianslug k

Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
Linux Test Simple by a13x4nd7u

This is a simple Linux commands test.
Linux Quiz by abhijangda

Trivia about your favorite OS
Linux Administration by typedeaF

Testing your knowledge of Linux administration tools, very light shell scripting, and good high level understanding of how the OS works at the user level. Anyone who has worked with Linux for 1-3 years should do good.
Linux Commands (Part 1) by nirus

If you think you know the linux command-line then this test is for you. For reference purposes, it is based on Debian/GNU Linux with a BASH Shell.

Related Links:
Ubuntu 5.10, Is Linux Ready for the Desktop?
So, Ive been running Ubuntu 5.10 since 2005-10-13, and I have a few thoughts on it.Thus far, my conclusion stands. Ubuntu is Debian with a lot of the sharp edges rounded off. And it just gets better with each release, really...
Software makers to send out network patrols
Symantec gets set to launch new intrusion detection software, as rival McAfee adds Linux support to its own corpo product...
Building a Linux Virtual Server
prostoalex writes NewsForge (an OSTG site) has an article that discusses the details of building a cluster for a virtual server - an environment where one can add and remove machines as needed, to account for high-traffic Web site of intensive databa..
Test Driving Linux
Michael J. Ross writes As Windows users hear more about Linux, they may be intrigued to give it a try, if only to learn what the buzz is about. But a major hurdle, possibly the most daunting, is how to obtain and install Linux on their PCs without di..
Mandriva Linux Security Update Advisory - wget (MDKSA-2005:098)
..
Windows to Have Better CLI
MickyJ writes The command line interface to the Windows Server OS will be changed to the new Monad Shell (MSH), in a phased implementation to take place over the next three to five years. It will exceed what has been delivered in Linux and Unix for m..
Linux Desktop Must Work to Head Off Straying Users
Opinion: You can talk all you want about how Mactels arent going to be that wonderful, but if you want to see many enterprise Linux desktops around in 2007, start making it happen...
Debian drops ball on security updates
The newly launched Linux distribution has been hit by a glitch--some versions were released with default security updates turned off...
Juggling Molecules with Linux
An anonymous reader writes This article at LinuxDevices.com describes an interesting project at the University of Vermont in which researchers use real-time Linux to build a laser trap that manipulates individual molecules by means of a computer-cont..
Could Apples Intel Desktop Threaten Linux?
esavard writes If Linux enthousiasts dont want Mac OSX on Intel to become a threat for the future of Linux Desktop, they must rethink the concept of Desktop has we know it today. Symphony OS did exactly that and propose some fresh concepts about how..
[?????] chmod 101
Unix 101
Configuring Tripwire
Guide to chmod


     
Your Ad Here
 
Copyright Open Source Institute, 2006