expect into remote system, get output to local shell variable -
i trying expect script ssh remote system, , output of remote command. want have output available locally. example, ssh system , local time output:
#!/usr/bin/expect -- set timeout 60 spawn ssh user@server.domain.com expect { timeout {puts "timed out after $timeout seconds"; exit} "password:" } send "supersecretpassword\r" expect "user$ " send "date\r" expect "date" expect "\r" set buffer1 '$expect_out(buffer)' expect "\r" set buffer2 '$expect_out(buffer)' send "exit\r" expect eof set buffer3 '$expect_out(buffer)' exit export variable $buffer1 export variable $buffer2 export variable $buffer3 echo "okay, done expecting..." echo "buffer1: $buffer1" echo "buffer2: $buffer2" echo "buffer3: $buffer3"
naturally, above isnt working, , in fact script execution ends after expect "exit"
#!/usr/bin/expect -- log_user 0 set timeout 60 spawn ssh user@server.domain.com expect { timeout {puts "timed out after $timeout seconds"; exit} "password:" } send "mypassword\r" expect "user$ " send "date\r" expect "date\r\n" expect "*\r" { send_user "$expect_out(0,string)\n" } close exit
Comments
Post a Comment