#!/usr/bin/expect -f
set ip [lindex $argv 0];
set password [lindex $argv 1]; 
set timeout 1
spawn ssh xuxm2007@$ip
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "$password\r" }
}
expect "*$*"      这一句不能省,尼玛
send "sudo su admin \r"
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*Password:" { send "$password\r" }
}

expect "*$*" 这一句不能省,尼玛
send "mkdir -p /home/admin/test \r"
send "cp -r /tmp/data /home/test \r"
send "exit\r"
send "exit\r"  别忘了是2层
expect eof

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2021-06-22
猜你喜欢
  • 2022-01-15
  • 2022-12-23
  • 2022-03-08
  • 2021-11-27
相关资源
相似解决方案