linuxでteratermマクロみたいなことがしたい  Net::SSH::Expect

CPANを使って、このへんのモジュールをインストールする

  • IO::Tty
  • Net::SSH::Expect



サンプルスクリプト

#!/usr/bin/env perl

use Net::SSH::Expect;

my $ssh = Net::SSH::Expect->new(
  host => "",
  password => "",
  user => "",
  raw_pty => 1
);

my $login_output = $ssh->login();

if($login_output !~ /\$ /){
  die "Login has filed. Login output was $login_output";
}

$ssh->exec("stty raw -echo");

my $ls = $ssh->exec("ls -l");

print $ls;

my $who = $ssh->exec("who");

print $who;

$ssh->close();

参照したURL:
http://y-kit.jp/saba/xp/cpan.htm
http://search.cpan.org/~bnegrao/Net-SSH-Expect-1.09/lib/Net/SSH/Expect.pod