I have noticed that my TCL/Expect Script is not writing to the Output Buffer.
`#!/usr/bin/expect -f
exp_internal 1; #Debug Expect
set username [lindex $argv 0]; #Takes Outside Argument
set password [lindex $argv 1]; #Takes Outside Argument
set hostFile [open hosts.txt r]; #Reads from a local file
while { [gets $hostFile hostname] >= 0 } {
spawn ssh -q -o StrictHostKeyChecking=no $username@$hostname
expect "password: "
send "$password\r"
expect "$ "
send "pbrun /bin/su -"
expect {
"Operations Team.*" {
puts "NewLine Was Caught After pbrun /bin/su - command"
#break #Exit While loop, which will exit the server since there is only one While Loop aprund the whole SSH Session
}
"Rejected.*" {
puts "NewLine & Return Carraige Was Caught After pbrun /bin/su - command"
#break #Exit While loop, which will exit the server since there is only one While Loop aprund the whole SSH Session
}
#"^" { ;#This command will work because in the expect only picks up a "^" character from the [send "pbrun /bin/su -"] command. This is an issues as the pbrun command has more ouput that just a "^", but expect only picks up the "^" character. You can use any other command like "ls", and expect does not write the ls command ouput to the buffer, only a newline character will be written to the buffer. This is an issue as I am unable to grab anything from expect.
# puts "Newline Character Met"
#}
}
send "hostname\r"
expect {
-re {".{8}[0-9]{5}"} {; #Never Works
puts "BUFFER:$expect_out(buffer):REFFUB"
}
"^" {; #Again, this will be met
puts "Newline Character Met"
}
}
}`
Any Help Is Much appreciated. I ran this in debug mode and indeed see that there is no output being written to the buffer for the
pbrun /bin/su -
or hostname
command except for the ^
character.
Asked by chromechris
(315 rep)
Feb 9, 2017, 02:35 AM
Last activity: Jul 7, 2021, 08:54 PM
Last activity: Jul 7, 2021, 08:54 PM