perl expect远程执行不了命令,请帮忙看看,谢谢了
时间:2011-01-14
来源:互联网
- foreach $remoteip(@ip)
- {
- print @ip;
- chomp;
- $exp = Expect->spawn($cmd,$remoteip) or die "Can't spawn $cmd! $!";
- $exp->log_file("output.log","w");
- $exp->send($usrname."\n") if $exp->expect($timeout,-re=>'[Ll]ogin');
- $exp->send("1111111\n") if $exp->expect($timeout,-re=>'word');
- if ($exp->expect($timeout,-re=>'$usrname>'))
- {
- $exp->send("/bin/date\r\n");
- print "hello \n";
- }
- }
Trying 00.000.000.00...
Connected to 00.000.000.00.
Escape character is '^]'.
Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel 2.6.16.60-0.21-bigsmp (4).
linux-bmlp login: ****
Password:
Last login: Fri Jan 14 18:00:14 CST 2011 from 00.000.000.00 on pts/4
hwoyh@linux-bmlp:/home/*****>
已经登陆成功了,可以打印出hello了,这何还不可以执行命令打印日期的。登陆成功后该如何执行命令?
请帮忙看看,谢谢

作者: oyhuan 发布时间: 2011-01-14
我想应该在
复制代码
中不需要 “\r\n"吧,
- $exp->send("/bin/date\r\n");
作者: climby 发布时间: 2011-01-14
QUOTE:
我想应该在中不需要 “\r\n"吧,
climby 发表于 2011-01-14 18:10
climby 发表于 2011-01-14 18:10
"\r\n","\r","\n",和不用这二个都试过都不行。
作者: oyhuan 发布时间: 2011-01-14
回复 oyhuan
那你吧Expect的debug 打开,
复制代码
看看debug提示什么信息。
那你吧Expect的debug 打开,
- $exp->debug(2);
作者: climby 发布时间: 2011-01-14
本帖最后由 oyhuan 于 2011-01-14 18:47 编辑
复制代码
DEBUG如下,不知道DEBUG放在哪里,我放了二个地方了
复制代码
QUOTE:
回复 oyhuan
那你吧Expect的debug 打开,看看debug提示什么信息。
climby 发表于 2011-01-14 18:36
那你吧Expect的debug 打开,看看debug提示什么信息。
climby 发表于 2011-01-14 18:36
- if ($exp->expect($timeout,-re=>'*****>'))
- {
- $exp->debug(2);
- $exp->send("/bin/date\n");
- $exp->debug(2);
- print "hello \n";
- }
- Closing spawn id(6).
- Expect::hard_close('Expect=GLOB(0x837841c)') called at /usr/lib/perl5/vendor_perl/5.8.3/Expect.pm line 1575
- Expect::DESTROY('Expect=GLOB(0x837841c)') called at ./expect.pl line 0
- eval {...} called at ./expect.pl line 0
- spawn id(6) closed.
- Pid 13844 of spawn id(6) terminated, Status: 0x01
作者: oyhuan 发布时间: 2011-01-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28