#!/usr/bin/expect set timeout 100 set host [lindex $argv 0] set username [lindex $argv 1] set password [lindex $argv 2] spawn scp -r file $username@$host:/路径/file expect { "(yes/no)?" { send "yes\n" expect "*assword:" { send "$password\n"} } "*assword:" { send "$password\n" } } expect "100%" expect eof
调用格式
expect ./scp.exp 参数1 参数2 参数3 expect ./scp/exp user 666666 192.169.1.100
网上有很多教程,不在赘述,需要注意的地方 { 前后必须要有空格!
原文链接:https://www.f2er.com/ubuntu/356060.html