SSH 自動輸入密碼執行命令

#!/usr/bin/expectssh

set host [lindex $argv 0]
set port [lindex $argv 1]
set user root
set password [lindex $argv 2]
set timeout -1
spawn scp -P $port file.sh $user@$host:/root/
expect {
   yes/no { send "yes\r"; exp_continue }
   *assword* { send "$password\r" }
}
spawn ssh -p $port $user@$host
expect "*assword:*"
send "$password\r"
expect $user@*  {send "ls -l \r" }
expect $user@*  {send "sh file.sh \r" }
expect $user@*  { send "exit\r" }
expect eofspa

相關文章
相關標籤/搜索