LinuxQuestions.org
Review your favorite Linux distribution.
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 01-07-2008, 04:56 PM   #1
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Rep: Reputation: 15
expect statement


All,

Im trying to write a program to ssh into a cisco box and run a certain command (write memory) on multiple devices. I think the best tool for this is using expect

Im not sure exactly sure how to write this code, but here is what im thinking:

#!/usr/bin/expect

log_user 0
spawn ssh cisco@192.168.0.1
expect "assword: "
send "password\r"
expect "\>" #shows the prompt of a cisco switch in enable mode
send "conf t"
expect "assword"
send "password\r"
expect "conf"
send "wr mem"
interact

Please let me know your thoughts

Thank you
 
Old 01-07-2008, 06:06 PM   #2
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
i figured out how to do this


#!/usr/bin/expect
spawn ssh user@192.168.0.1
expect "user@192.168.0.1's password:"
send "passwd\r"
expect ">"
send "en\r"
expect "Password:"
send "passwd\r"
expect "#"
send "conf t\r"
expect "#(config)"
send "wr m\r"
expect "#(config)"
 
Old 04-28-2008, 10:21 PM   #3
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
website

this is also on our site:

http://blog.noynim.com
 
  


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
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM
About Expect shan_nathan Programming 2 09-25-2007 09:29 PM
expect newbie_adm Linux - Newbie 1 06-07-2006 01:23 AM
expect - any other way? rooksin Programming 1 03-09-2006 10:26 PM
expect sk8guitar Programming 3 07-29-2003 09:24 PM

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

All times are GMT -5. The time now is 09:43 AM.

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