[[
PerlからSSH
]]
Fool For the City
現在位置:
なみかわみやこの技術メモwikiです。
»
perl
»
PerlからSSH
文書の表示
以前のリビジョン
最近の変更
索引
ログイン
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== PerlからSSH ====== DAGのrepoを追加 <code> rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm </code> Net:SSHを追加 <code> yum --enablerepo=rpmforge install perl-Net-SSH-Perl </code> yumでインストールされないモジュールを追加 <code> perl -MCPAN -e shell install Math::BigInt install Math::BigInt::GMP </code> サンプルコード <code> #!/usr/bin/perl use strict; use Net::SSH::Perl; use Net::SSH::Perl::Constants qw(:msg); my $ssh = Net::SSH::Perl->new("HOSTNAME"); $ssh->login("USERNAME", "PASSWORD"); my ($stdout, $stderr, $exit) = $ssh->cmd('cat /etc/redhat-release'); print $stdout; $ssh->cmd("exit"); </code> しかし、この状態では2度目にコードを実行したらエラーとなるのです ライブラリを修正して対応せう <code> cd /usr/lib/perl5/vendor_perl/5.8.8/Net/SSH/ cp -p Perl.pm Perl.pm.ORG </code> 237行目付近に <code> if ($! =~ /Address already in use/i) { </code> というコードがありますので以下の通り書換えます。 <code> #if ($! =~ /Address already in use/i) { if ($! =~ /(Address|The socket name is) already in use/i || $! =~ /アドレスは既に/) { </code>
perl/ssh.1285754178.txt.gz · 最終更新: 2010/09/29 09:56 by miyako
文書の表示
以前のリビジョン
文書の先頭へ