Hello,
I already know how to read from a list of devices and log in to issue commands via expect, based on a list of commands for each specific device, like this:
Code:
set USER [lindex $argv 0]
set PASS [lindex $argv 1]
set NODE [lindex $argv 2]
set timeout 15
set LOAD_CMD [open "./cpe_check-files/rad-commands.txt" r]
set CMD_LIST [split [read $LOAD_CMD] "\n"]
close $LOAD_CMD
spawn ssh $USER@$NODE
expect {
timeout {
puts "\n\n##### $NODE - UNREACHABLE #####\n"; exit 3
}
-re ".*Are.*.*yes.*no.*" {
send "yes\r"
}
"password:" {
send "$PASS\r"
}
}
foreach COMMAND $CMD_LIST {
if {$COMMAND != ""} {
expect {
"# $" {send "$COMMAND\r"; break}
}
}
}
expect *# {
send -- "logout\r"
}
close
~
And I also know how to compensate for a device where you cannot set terminal length to 0, like this:
Code:
set NODE [lindex $argv 0]
set USER [lindex $argv 1]
set PASS [lindex $argv 2]
set timeout 30
spawn ssh -o "StrictHostKeyChecking no" $NODE
expect {*assword: } {}\
timeout {puts "\n\n**** INCORRECT LOGIN ****\n\n"; exit 3}
send "$PASS\n"
expect {*#} {}\
timeout {puts "\n\n**** PASSWORD INCORRECT ****\n\n"; exit 3}
send "info\r"
while (1) {
expect {
timeout break
"more.." {send " "}
"# $" {send "logout\r"; break}
}
}
But I am having a terrible time trying to combine these two things. I have a list of commands that may vary for a given device (hence the reading the commands from a list thing). The length of the output of each of these commands may end up being longer than the terminal allows, so a "more.." prompt will be seen. At that point, a human being would have to press the space bar to show the rest of the output until it is finished and gets back to the "#" prompt. I need the expect script to both read the commands from a list, then for each command, send a space any time it sees "more.." in the output, and move on to the next command until they are done, then log out. The device has a bug in it where if you set the terminal length to 0, it will stay tat way forever until the device is rebooted, so I cannot simply add "term len 0" or anything like that to the script.
Any help would be greatly appreciated.
Thanks in Advance,
Wolverene13