shell调用expect实现scp自动密码输入

  sre
#!/bin/bash

scpHOST=192.168.52.133
scpPORT=22
scpUSER=root
scpKEY=123456
scpHOME=/opt/ftp/


scpFILE="scp.sh"

expect -c "
set timeout 600;
spawn /usr/bin/scp -P {scpPORT}{scpFILE} {scpUSER}@{scpHOST}:{scpHOME}
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"{scpKEY}\r\";}
}
expect eof;"

LEAVE A COMMENT

Captcha Code