UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old February 1st, 2005, 02:25 PM
getwithrob getwithrob is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 getwithrob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 48 sec
Reputation Power: 0
Need some help on an Expect Script

To start. I'm a terrible programmer. The expect script came from someone else but I can't get it working. Please help.

Here's the deal. I have a file with a bunch of IP addresses. I took everything out except for three to show you what I'm trying to do. This file contains addresses of a bunch of routers and switches. Most have TACACs configured but some don't. I'm trying to identify the ones that aren't configured. If the device has TACACs, when telneting, it will prompt for Username: - If it doesn't have TACACs, it will prompt for Password: -.

Here's the error message when I try to execute the dolist script.

$ ./dolist
/export/home/rjohnson/expectstuff/getnodeinfo: syntax error at line 26: `}' unexpected
/export/home/rjohnson/expectstuff/getnodeinfo: syntax error at line 26: `}' unexpected
/export/home/rjohnson/expectstuff/getnodeinfo: syntax error at line 26: `}' unexpected
$


The scripts are shown below.
$ pwd
/export/home/rjohnson/expectstuff
$ ls
dolist getnodeinfo list script.original
$ more dolist
#!/bin/sh
for device in `cat /export/home/rjohnson/expectstuff/list`
do
/export/home/rjohnson/expectstuff/getnodeinfo $device
done
$ more list
10.21.21.13
10.21.21.11
10.21.253.11
$ more getnodeinfo
set username "ciscoworks"
set password "just4us"
while { $n < 5 } {
spawn "/bin/sh"
send "telnet $HOSTNAME\r"
sleep 1
expect "Username:"
send "$username\r"
expect "Password"
send "$password\r"
send "\r\r"
"Welcome" {
incr pass0
set n 5
set p 0
close
}
"from" {
send "id\r"
expect {
$username {
incr pass0
set n 5
close
}
}
}
"login: $" {
set pass1 0
puts stdout "Expect return: $expect_out(0,string)"
puts stdout "Failed login"
send "\x1d\x0d"
expect "telnet"
send "close\r"
send "quit\r"
close
}
}
incr n
}
$

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Need some help on an Expect Script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway