1

I am trying to write the output of the netcat command including the command also to a file by logging into remote servers. But it is not writing. What am I missing ?

#!/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 $user@mydomain.com     
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.