为什么期望脚本的输出不写入日志

为什么期望脚本的输出不写入日志

我正在尝试通过登录远程服务器将 netcat 命令的输出(包括该命令)写入文件。但这不是写作。我缺少什么?

#!/usr/bin/expect -f
set user [lindex $argv 0]

stty -echo 
send_user "Password: " 
expect_user -re "(.*)\n" 
set passwd $expect_out(1,string) 
send_user "\n" 
stty echo

set output [open "outputfile.txt" "a+"] 
spawn ssh [email protected]     
expect {        
   "yes/no" {       
        send "yes\r"        
        exp_continue        
     }
}

expect -exact "$user@mydomain's password: " 
sleep 2  
send -- "$passwd\r" 
sleep 5

expect -re $ 
puts $output "myhost ---> destinatin" 
send "nc -zv -w 1 XX.XX.XX.XX 443\n"

sleep 10 

expect "*$"
set outcome $expect_out(buffer) 
send "\r" 

puts $output $outcome


send "logout\r"

close $output

expect eof
exit 0

相关内容