I've tried pretty much every combination. It seems like ofnuts is right, it's something wrong earlier on in my script. I've eliminated the question mark all together by sending a different command to the switch that gives me the output that I need. What I'm getting right now is this...
send: spawn id exp6 not open
while executing
"send "dir all-filesystems\r""
(file ./batch_ssh.exp" line 41)
When I look at the output file I created all I see is the switch doing the initial "dir flash:" Then the script times out. Here's what I've got written into the script currently.
Code:
#!/usr/bin/expect -f
# Bj Howell
# June 3, 2013
# Upgrades the IOS on a list of systems.
set timeout 700
set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
spawn ssh -o StrictHostKeyChecking=no $user@$host
expect "password:"
send "$pass\r"
expect "*#"
#Checks to see if it has the new code. If it does, it schedules a reboot and sets the boot statement.
send "dir flash:\r"
expect {
"*c3750-ipservicesk9-mz.122.55.SE5"{}
"*c3750-ipservicesk9-mz.122-55.SE7.bin"{
send "conf t\r"
expect "*(config)#"
send "boot system flash:c3750-ipservicesk9-mz.122-55.SE7.bin\r"
expect "*(config)#"
send "exit\r"
expect "*#"
send "reload at 02:00 8 June\r"
expect "System configuration has been modified. Save? [yes/no]:"
send "yes\r"
expect "Proceed with reload? [confirm]"
send "\r"
expect "*#"
send "wr\r"
expect "*#"
send "exit\r"
expect eof
}
}
# checks to see if there are other members in the stack, and if there are it will delete the IOS off of each member.
send "dir all-filesystems\r"
expect {
"Directory of flash:/"{
send "delete /force /recursive flash1:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash1:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash2:/"{
send "delete /force /recursive flash2:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash2:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash3:/"{
send "delete /force /recursive flash3:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash3:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash4:/"{
send "delete /force /recursive flash4:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash4:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash5:/"{
send "delete /force /recursive flash5:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash5:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash6:/"{
send "delete /force /recursive flash6:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash6:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash7:/"{
send "delete /force /recursive flash7:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash7:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash8:/"{
send "delete /force /recursive flash8:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash8:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash9:/"{
send "delete /force /recursive flash9:c3750-ipservicesk9-mz.122-55.SE5\r"
expect "*#"
send "delete /force /recursive flash9:c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
}
#This deletes the IOS from a single device, then tftps the IOS to flash. If the TFTP fails it tries one more time.
send "copy tftp: flash:\r"
expect "Address or name of remote host []?"
send "204.208.204.209\r"
expect "Source filename []?"
send "c3750-ipservicesk9-mz.122-55.SE7.bin\r"
expect "Destination filename [c3750-ipservicesk9-mz.122-55.SE7.bin]?"
send "c3750-ipservicesk9-mz.122-55.SE7.bin\r"
expect {
"[OK - 12750343 bytes]"{}
"[timed out]"{
send "copy tftp: flash:\r"
expect "Address or name of remote host []?"
send "204.208.204.209\r"
expect "Source filename []?"
send "c3750-ipservicesk9-mz.122-55.SE7.bin\r"
expect "Destination filename [c3750-ipservicesk9-mz.122-55.SE7.bin]?"
send "c3750-ipservicesk9-mz.122-55.SE7.bin\r"
expect "[OK - 12750343 bytes]"
}
}
# checks to see if there are other members in the stack, and if there are it will copy the ios from flash1 to the other devices.
send "dir all-filesystems\r"
expect {
"Directory of flash2:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash2:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash3:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash3:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash4:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash4:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash5:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash5:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash6:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash6:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash7:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash7:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash8:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash8:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
"Directory of flash9:/"{
send "copy flash1:c3750-ipservicesk9-mz.122-55.SE7.bin flash9:\r"
expect "Destination filename"
send "c3750-ipservicesk9-mz.122-55.SE5.bin\r"
expect "*#"
}
}
# Sets the boot statement for the stack
send "conf t\r"
expect "*(config)#"
send "boot system flash:c3750-ipservicesk9-mz.122-55.SE7.bin\r"
expect "*(config)#"
send "exit"
expect "*#"
#sets the reload time, writes everything to memory, then exits.
send "reload at 02:00 8 June\r"
expect "System configuration has been modified. Save? [yes/no]:"
send "yes\r"
expect "Proceed with reload? [confirm]"
send "\r"
expect "*#"
send "wr mem\r"
expect "*#"
send "exit\r"
expect eof