您的位置:首页 > 其它

sch远程拷贝自动输入密码expect小脚本

2014-05-04 17:30 393 查看
#!/usr/bin/expect
#Author Aladin
#date 20140504
#auto input passwd
#Version 1.0
spawn scp -P22 /root/shell_test/123.txt root@192.168.0.80:/tmp/
set timeout 100
expect "root@192.168.0.80's password:"
set timeout 10
send "123456\r"
#expect eof
interact

#注意:服务器需要安装expect
一、源码包安装要安装expect,linux expect的安装1.安装相应的包 yum install -y tcl tclx tcl-devel2.下载expect-5.43.tar.gz包(我这里用的这个包,大家也可以用别的)根据参数,运行./configure
./configure --with-tcl=/usr/lib --with-tclinclude=/usr/include/tcl-private/generic
3.make && make install 安装完毕
二、yum 安装 yum install -y expect
问题处理:
./auto_scpfile.sh: line 2: spawn: command not found
couldn't read file "password:": no such file or directory
./auto_scpfile.sh: line 8: send: command not found
./auto_scpfile.sh: line 10: interact: command not found
这样的话,脚本要指定expect: #!/usr/bin/expect
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息