- 论坛徽章:
- 0
|
本帖最后由 Run_LeoCat 于 2013-02-14 15:57 编辑
HELLO,咨询个问题哈,关于perl的telnet的问题,我看了你的回复和帖子,实验过程中,出现以下问题,本人小白,不知什么原因,特向您请教,具体如下:
脚本:
use strict;
use warnings;
use Net::Telnet;
my $tnet=new Net::Telnet('Host'=>'192.168.56.113','Timeout'=>30,'Dump_Log'=>'test.log');
$tnet->waitfor('Match'=>"/login: /");
$tnet->print("leoliu");
$tnet->waitfor('Match'=>"/Password: /");
$tnet->print("leoliu");
$tnet->waitfor('/[\$%#>:]/');
#$tnet->print("ls");
#my $data=$tnet->get('Timeout'=>9999999);
my @lines=$tnet->cmd('String'=>"ls -l");
print(@lines);
$tnet->errmode("return");
#print($data);
$tnet->print("exit");
$tnet->close();
执行结果:
base:/home/perltest # perl t1.perl
ls -l
日志中的内容:
[leoliu@localhost ~]base:/home/perltest # more test.log
< 0x00000: ff fd 18 ff fd 20 ff fd 23 ff fd 27 . #'
> 0x00000: ff fc 18 ff fc 20 ff fc 23 ff fc 27 . #'
< 0x00000: ff fb 03 ff fd 01 ff fd 1f ff fb 05 ff fd 21 ....!
> 0x00000: ff fd 03 ff fc 01 ff fc 1f ff fe 05 ff fc 21 ....!
< 0x00000: ff fb 01 43 65 6e 74 4f 53 20 72 65 6c 65 61 73 .CentOS releas
< 0x00010: 65 20 35 2e 38 20 28 46 69 6e 61 6c 29 0d 0a 4b e 5.8 (Final)..K
< 0x00020: 65 72 6e 65 6c 20 32 2e 36 2e 31 38 2d 33 30 38 ernel 2.6.18-308
< 0x00030: 2e 65 6c 35 20 6f 6e 20 61 6e 20 69 36 38 36 0d .el5 on an i686.
< 0x00040: 0a .
> 0x00000: ff fd 01 .
< 0x00000: 6c 6f 67 69 6e 3a 20 login:
> 0x00000: 6c 65 6f 6c 69 75 0d 0a leoliu..
< 0x00000: 6c 65 6f 6c 69 75 0d 0a leoliu..
< 0x00000: 50 61 73 73 77 6f 72 64 3a 20 Password:
> 0x00000: 6c 65 6f 6c 69 75 0d 0a leoliu..
< 0x00000: 0d 0a ..
< 0x00000: 4c 61 73 74 20 6c 6f 67 69 6e 3a 20 54 68 75 20 Last login: Thu
< 0x00010: 46 65 62 20 31 34 20 31 35 3a 33 30 3a 30 36 20 Feb 14 15:30:06
< 0x00020: 66 72 6f 6d 20 31 39 32 2e 31 36 38 2e 35 36 2e from 192.168.56.
< 0x00030: 31 30 0d 0a 10..
> 0x00000: 6c 73 20 2d 6c 0d 0a ls -l..
< 0x00000: 6c 73 20 2d 6c 0d 0a ls -l..
< 0x00000: 5b 6c 65 6f 6c 69 75 40 6c 6f 63 61 6c 68 6f 73 [leoliu@localhos
< 0x00010: 74 20 7e 5d 24 20 t ~]$
> 0x00000: 65 78 69 74 0d 0a exit..
我不明白,为什么ls的命令在登入系统以前就执行了,以及如何能够避免此问题从而达到自己的目的呢?
谢谢,不胜感激。 |
|