Linux基于expect(tcl)实现shell自动交互
2017-07-11 08:44
656 查看
1、需求:在shell中执行scp命令时,可以自动输入密码,而不用手工交互输入。
2、方案:采用expect来实现。
Expect是一个基于TCL开发出的语言包。
而TCL(Tool Command Language)工具脚本语言,是Linux内的一种语言包。
执行shell脚本,要先安装tcl和expect,安装次序先tcl后expect,expect依赖tcl。
1)tcl官网:http://www.tcl.tk/
2)expect官网:http://expect.sourceforge.net/
下载相应包后解压make install即可。
3、脚本:shell
#!bin/sh
expect<<EOF
set timeout 200
spawn scp -R /tmp/test.txt username@ip:/tmp
expect "password:"
send "123456\r"
expect eof
EOF
其中要复制的目的端主机,用户名是username,密码是123456。
有兴趣可以继续研究expect。
2、方案:采用expect来实现。
Expect是一个基于TCL开发出的语言包。
而TCL(Tool Command Language)工具脚本语言,是Linux内的一种语言包。
执行shell脚本,要先安装tcl和expect,安装次序先tcl后expect,expect依赖tcl。
1)tcl官网:http://www.tcl.tk/
2)expect官网:http://expect.sourceforge.net/
下载相应包后解压make install即可。
3、脚本:shell
#!bin/sh
expect<<EOF
set timeout 200
spawn scp -R /tmp/test.txt username@ip:/tmp
expect "password:"
send "123456\r"
expect eof
EOF
其中要复制的目的端主机,用户名是username,密码是123456。
有兴趣可以继续研究expect。
相关文章推荐
- UNIX/LINUX使用expect实现人机自动交互功能
- shell脚本调用expect命令实现命令行自动交互
- 使用expect实现shell自动交互
- 用expect实现shell脚本的自动交互
- linux自动交互工具expect,tcl安装和安装包,以及自动互信脚本
- 使用expect实现shell自动交互
- linux自动交互工具expect,tcl安装和安装包,以及自动互信脚本
- [转载]使用expect实现shell自动交互
- 使用expect实现shell自动交互
- Linux-----Shell脚本交互实现自动输入密码
- 【转】使用expect实现shell自动交互
- shell脚本调用expect命令实现命令行自动交互
- 使用expect实现shell自动交互
- 使用expect实现shell自动交互
- 使用expect实现shell自动交互
- Linux使用Shell脚本实现ftp的自动上传下载
- Linux使用Shell脚本实现ftp的自动上传下载
- 基于cron、rsync和ssh免密码登录实现Linux系统间自动同步~
- linux下实现ftp自动备份shell脚本
- shell+expect实现多台服务器自动运行脚本。