linux使用expect后的窗口改变问题
2012-12-21 15:07
2291 查看
使用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:
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写和程序,先让我们来看看问题的现象.
普通的自动登陆的程序
测试 #expect test.exp 工作的很好,只是当窗口发生改变时,会出问题,如下
现在我们根据上面perl中讲到的修改这个,让窗口改变的信号也能传送到远程服务器 修复后的expect.
以上转自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
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 expect set server xxx.xxx.xxx.xxx set user root set passwd ******* spawn ssh $user@$server expect -re "password:" send "${passwd}\r" expect -re "$" # 给操作权还回给用户 interact
测试 #expect test.exp 工作的很好,只是当窗口发生改变时,会出问题,如下
现在我们根据上面perl中讲到的修改这个,让窗口改变的信号也能传送到远程服务器 修复后的expect.
#!/usr/bin/env expect #trap sigwinch spawned trap { set rows [stty rows] set cols [stty columns] stty rows $rows columns $cols < $spawn_out(slave,name) } WINCH set server xxx.xxx.xxx.xxx set user root set passwd ******* spawn ssh $user@$server expect -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
相关文章推荐
- 解决使用seletor点击改变背景时事件被上层布局获取的问题
- Linux系统下Vim的多窗口使用技巧
- 解决linux系统下因分区目录划分过小,导致tomcat使用系统临时文件夹(/tmp)没有足够空间而报错的问题
- 使用mongodb Dos命令窗口时发生中文不支持问题
- Linux 下第一次使用MySQL遇到几种问题。
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- linux中expect的使用
- js2:事件的学习,弹出窗口,状态栏字改变,地图热点的使用
- linux expect的使用详解,实例
- linux问题-CentOS7中搭建HTTP,FTP服务,改变提示颜色
- 如何解决在linux下使用wget或curl下载jdk失败的问题
- 在Linux 6上使用UDEV解决 ASM存储设备问题( single path)
- linux下Oracle通过设置大内存页解决使用swap分区问题
- 使用HorizontalScrollView和ViewPager联动效果出现的position值改变问题
- Linux 连接oracle 时,无法使用回退键问题
- linux下使用dnw烧写及其出现问题的解答
- 解决Linux下ifconfig、shutdown等Shell命令不能使用的问题
- 使用Linux raw socket时需要注意的一些问题
- linux下安装过zsh后,使用yum安装autojump后,使用source ./zshrc出现问题
- Linux下使用Shell脚本改变当前工作路径