1、apt-get install expect
2、编写shell脚本test.sh
#!/usr/bin/expect -f
#!/bin/sh
set password 1
spawn scp root@192.168.1.93:/opt/ybs/bin/YSNY.pyc /opt/ybs/bin/
set timeout 10;
expect {
yes/no {send yes\n;exp_continue};
password: {send $password\n};
}
set timeout 10;
send exit\n;
expect eof;