Mar 25, 2009

perl telnet cisco router script

use Net::Telnet::Cisco;
my $session = Net::Telnet::Cisco->new(Host => '192.168.1.1');
$session->login('xxx', 'xxx');
# Execute a command
my @output = $session->cmd('show version');
print @output;
# Enable mode
if ($session->enable("enable_password") ) {
@output = $session->cmd('show privilege');
print "My privileges: @output\n";
} else {
warn "Can't enable: " . $session->errmsg;
}
$session->close;

perl 中文 string split by use encoding big5

Perl 處理中文, 加入

use encoding big5;
$string="中文成功123";
後, split(//,$string); 即可拆成 "中","文","成","功","1","2","3"

若是從資料庫取得的字串, 可試試
$string=decode("big5", $string);
再做 @str=split(//,$string);

Mar 19, 2009

perl telnet script

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt => '/\$|#|%|>/');
$telnet->open('192.168.1.1');
$telnet->login('root','tttt');
print $telnet->cmd('who');
print $telnet->cmd('ps -ef | grep ora_ | wc -l');

Activeperl ssh

Activeperl , type ppm to explore Perl Package Manager ,
search net-ssh-perl , if cannot find , then edit the preference , add other repository.

Choose mark for install , you will find warning message .
Install all of it before install net-ssh-perl.

And then comment out line 216 at 'dir'\net\ssh\perl.pm
# defined($sock->blocking(0))
# or die "Can't set socket non-blocking: $!";

then can try following ssh test script.

use Net::SSH::Perl ;
my $ssh = Net::SSH::Perl->new("192.168.1.1");
$ssh->login("root", "bbb");
my($stdout,$stderr,$exit)=$ssh -> cmd("ls");
print $stdout;