expect笔记
#!/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