Hello all,
I am afraid I am at a deadend and could really use a helping hand. I have a frankenstein'd expect script that ssh's into a server, changes directory and outputs an 'ls' to a text file. Ideally I want to pass the output to a variable that goes into a larger bash script. Right now the txt file returns the ls command, the output and then the prompt again before exiting. I only want the output obviously. If anyone can lend a hand that would be great. Here's the script:
Code:
#!/usr/bin/expect -f
set prompt "((%|#|\\$| :) |>|])$"
if [info exists env(EXPECT_PROMPT)] {
set prompt $env(EXPECT_PROMPT)
}
set timeout 5
set user [lindex $argv 0]
#set command [lindex $argv 1]
set host [lindex $argv 1]
set log [open "log.txt" "w"]
if {[llength $argv] != 2} {
puts stderr "Usage: $argv0 <username> <host>\n"
exit }
exp_internal 1
send_user "ssh Password: "
set timeout -1
stty -echo
expect_user -re "(.*)\n"
set password $expect_out(1,string)
send_user "\n"
spawn ssh -l $user $host
expect {
"*yes/no*"
{ send -- "yes\r" }
"*?assword:*"
{ send -- "$password\r" }
}
#expect -timeout 30 -nocase "*assword:"
#send "$password\r"
sleep 5
#expect -re $prompt
send "cd ../../domains\r"
sleep 5
expect -re $prompt
expect "$ "
exp_send "ls\r"
expect "$ "
sleep 5
set outcome $expect_out(buffer)
puts $log $outcome
sleep 5
send "exit\r"
expect eof