由于expect是基于tcl的,所以首先要安装tcl
我的环境是RHEL 6 + expect-5.43.0 + tcl8.4.19
首先tcl:
tar zxvf tcl8.4.19-src.tar.gz
cd tcl8.4.19/unix/
./configure
make && make install
安装完后pwd一下,等下configure expect时需要用到
然后expect:
tar zxvf expect-5.43.0.tar.gz
cd expect-5.43
#此处 --with-tclinclude 的路径为tcl目录下generic的绝对路径
./configure --with-tclinclude=/home/dev/software/tcl8.4.19/generic/ --with-tclconfig=/usr/local/lib/
make && make install
完成安装后,输入expect可以验证是否已经安装好
通过简单脚本就可以实现自动输入密码了:
#!/bin/bash
expect -c "
set timeout 5;
spawn /usr/bin/scp -r /home/dev/log dev@192.168.1.192:/home/dev/
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"yourpassword\r\";} #修改成远程主机用户的密码
}
expect eof;"
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29773961/viewspace-1465740/
,如需转载,请注明出处,否则将追究法律责任。