1、下载yum
yum install expect
2、编辑创建脚本 vim scpshell.sh
#!/bin/sh # 传输的文件 bushufiles=test.zip #传到来存储的路径 filepath=`pwd` expect -c " spawn scp -r root@192.168.31.111:/root/ ${bushufiles} ${filepath} expect { \"yes/no\" {send \"yes\r\"; exp_continue;} \"*password*\" {set timeout 300; send \"123456\r\";} } expect eof"
3、授权
chmod +x scpshell.sh
4、执行
sh scpshell.sh