linux使用expect后的窗口改变问题
来源:互联网 发布:2017年全国癌症数据 编辑:程序博客网 时间:2024/05/14 22:33
使用expect做自动login,一直有个麻烦的问题.就是当本地的终端窗口大小发生改变时,因为使用了expect,没法传送改变窗口的信号到远程机器上面,所以看起来很奇怪,严重影响工作的效率. 以前在perl上解决过,perl上对这个问题的详解如下 I set the terminal size as explained above, but if I resize the window, the application does not notice this. You have to catch the signal WINCH ("window size changed"), change the terminal size and propagate the signal to the spawned application:
my $exp = new Expect;$exp->slave->clone_winsize_from(\*STDIN);$exp->spawn("ssh somehost);$SIG{WINCH} = \&winch;sub winch { $exp->slave->clone_winsize_from(\*STDIN); kill WINCH => $exp->pid if $exp->pid; $SIG{WINCH} = \&winch;}$exp->interact();
There is an example file ssh.pl in the examples/ subdir that shows how this works with ssh. Please note that I do strongly object against using Expect to automate ssh login, as there are better way to do that (see ssh-keygen). 现在我们使用expect写和程序,先让我们来看看问题的现象. 普通的自动登陆的程序
#!/usr/bin/env expectset server xxx.xxx.xxx.xxxset user rootset passwd *******spawn ssh $user@$serverexpect -re "password:"send "${passwd}\r"expect -re "$"# 给操作权还回给用户interact
测试 #expect test.exp 工作的很好,只是当窗口发生改变时,会出问题,如下
现在我们根据上面perl中讲到的修改这个,让窗口改变的信号也能传送到远程服务器 修复后的expect.
#!/usr/bin/env expect #trap sigwinch spawnedtrap { set rows [stty rows] set cols [stty columns] stty rows $rows columns $cols < $spawn_out(slave,name)} WINCHset server xxx.xxx.xxx.xxxset user rootset passwd *******spawn ssh $user@$serverexpect -re "password:"send "${passwd}\r"expect -re "$"# 给操作权还回给用户interact
以上转自http://www.php-oa.com/2009/08/11/expect-window-size-changed.html
我个人的实例:
#!/usr/bin/expect
#trap sigwinch spawned
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
#set timeout 10
spawn ssh root@(you ip)
expect "password"
send "(your password)\r"
interact
- linux使用expect后的窗口改变问题
- linux expect的使用
- linux 下 expect 的使用
- linux 下expect的使用
- linux expect的使用详解
- linux expect的使用详解
- linux expect的使用详解
- linux expect的使用详解
- linux expect的使用详解
- linux中expect的使用
- 关于expect使用ssh的问题
- 关于expect使用ssh的问题
- linux expect的使用详解,实例
- linux expect的使用详解,实例
- Linux下expect的安装和使用
- linux expect的使用详解,实例
- Linux expect使用,用户交互的福音
- linux 使用expect
- 获得通讯录中联系人的所有属性
- 两分钟彻底让你明白Android Activity生命周期(图文)!
- Python操作Excel
- Unity界面插件NGUI核心组件说明
- ios实现通讯录的查询与删除
- linux使用expect后的窗口改变问题
- 程序员技术练级攻略 .
- cocos2d---粒子效果1
- 给gridview动态生成radiobutton添加OnCheckedChanged事件
- vs2010新功能(转)
- Oracle GoldenGate DDL Synchronization configuration
- 使用科大迅飞语音开发时的一系列问题及解决办法
- JavaScript浏览器对象之一Window对象
- 页面 百分比进度条