标题有点绕口~

#!/usr/bin/expect -f

if { $argc<4 } {
    puts stderr "Usage: $argv0 <host> <user> <passwd> <cmd>"
    exit 1   
}

set HOST [lindex $argv 0]
set USER [lindex $argv 1]
set PSWD [lindex $argv 2]
set CMDS [lindex $argv 3]

log_user 0
set timeout 3
spawn -noecho ssh $USER@$HOST "$CMDS"
while {1} {
    expect {
        "(yes/no)? " { send "yes\r"; continue; }
        "Password: " { send "$PSWD\r"; log_user 1 }
        eof { break }
        timeout { send_user "\[timeout\]\n"; exit 255 }
    }
}

 

 

相关文章:

  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2022-02-26
  • 2022-02-22
  • 2022-12-23
猜你喜欢
  • 2021-12-25
  • 2022-02-13
  • 2022-02-07
  • 2022-02-07
  • 2021-05-20
  • 2021-11-28
相关资源
相似解决方案