|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 } $ |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Need some help on an Expect Script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|