因為有need用ssh連到別的主機做些指令,原本可以用expect來處理的,但看到perl 有ssh 和telnet 二個模組可以用,就想用ssh來做這樣的功能
首先要安裝Net::SSH::Perl這個模組, 用下面指令install
下載SSH模組請按此
#tar xvf Net-SSH-Perl-1.30.tar.gz
#cd Net-SSH-Perl-1.30
#perl Makefile.PL
之後會出現以下畫面
This is Net::SSH::Perl.
As of version 1.00, Net::SSH::Perl supports both the SSH1 and
SSH2 protocols natively. The two protocols have different
module prerequisitives, so you need to decide which protocol(s)
you plan to use. If you use one or the other, only those modules
for your chosen protocol will be installed; if you choose both,
all of the supporting modules will be installed. Please choose
the protocols you'd like to use from the following list ("Both"
is the default).
[1] SSH1
[2] SSH2
[3] Both SSH1 and SSH2
Which protocol(s) do you plan to use? [3] 3
Some of the Net::SSH::Perl ciphers depend on a Crypt:: module from
CPAN. You may already have the necessary modules installed, in which
case you don't need to bother with this step. Otherwise you'll need
to install at least one cipher to use Net::SSH::Perl. Please choose
at least one from the following list (Crypt::IDEA is the default).
[1] IDEA
[2] DES
[3] DES3
[4] Blowfish
[5] RC4
Enter your choices, separated by spaces: [1] 1
Checking for optional modules
Digest::BubbleBabble is required if you want to generate bubble babble
key fingerprints with pssh-keygen.
Would you like to install it? (y/n) [y]
Crypt::RSA is required if you wish to use the ssh-rsa public
key algorithm (ssh-dss is used by default).
Would you like to install it? (y/n) [y]
Checking if your kit is complete...
Looks good
Warning: prerequisite Convert::PEM 0.05 not found.
Warning: prerequisite Crypt::DH 0.01 not found.
Warning: prerequisite Crypt::DSA 0.11 not found.
Warning: prerequisite Crypt::IDEA 0 not found.
Warning: prerequisite Crypt::RSA 1.37 not found.
Warning: prerequisite Digest::BubbleBabble 0.01 not found.
Warning: prerequisite Digest::HMAC_MD5 0 not found.
Warning: prerequisite Digest::HMAC_SHA1 0 not found.
Warning: prerequisite Digest::SHA1 2.10 not found.
Warning: prerequisite Math::GMP 1.04 not found.
Warning: prerequisite Math::Pari 2.001804 not found.
Writing Makefile for Net::SSH::Perl
以上訊息表示上面的模組都要裝
可以用 cpan -i model_name 去處理
全裝好後再下
#perl Makefile.PL
#make
#make install
這樣就安裝好了
以下用簡單的sample來說明 ssh模組的用法
用codes來說明
use Net::SSH::Perl ;
my $ssh = Net::SSH::Perl->new("IP_address");
$ssh->login("username", "passord");
#要執行的指令寫在此即可
$ssh->cmd("touch abc.txt");
首先要安裝Net::SSH::Perl這個模組, 用下面指令install
下載SSH模組請按此
#tar xvf Net-SSH-Perl-1.30.tar.gz
#cd Net-SSH-Perl-1.30
#perl Makefile.PL
之後會出現以下畫面
This is Net::SSH::Perl.
As of version 1.00, Net::SSH::Perl supports both the SSH1 and
SSH2 protocols natively. The two protocols have different
module prerequisitives, so you need to decide which protocol(s)
you plan to use. If you use one or the other, only those modules
for your chosen protocol will be installed; if you choose both,
all of the supporting modules will be installed. Please choose
the protocols you'd like to use from the following list ("Both"
is the default).
[1] SSH1
[2] SSH2
[3] Both SSH1 and SSH2
Which protocol(s) do you plan to use? [3] 3
Some of the Net::SSH::Perl ciphers depend on a Crypt:: module from
CPAN. You may already have the necessary modules installed, in which
case you don't need to bother with this step. Otherwise you'll need
to install at least one cipher to use Net::SSH::Perl. Please choose
at least one from the following list (Crypt::IDEA is the default).
[1] IDEA
[2] DES
[3] DES3
[4] Blowfish
[5] RC4
Enter your choices, separated by spaces: [1] 1
Checking for optional modules
Digest::BubbleBabble is required if you want to generate bubble babble
key fingerprints with pssh-keygen.
Would you like to install it? (y/n) [y]
Crypt::RSA is required if you wish to use the ssh-rsa public
key algorithm (ssh-dss is used by default).
Would you like to install it? (y/n) [y]
Checking if your kit is complete...
Looks good
Warning: prerequisite Convert::PEM 0.05 not found.
Warning: prerequisite Crypt::DH 0.01 not found.
Warning: prerequisite Crypt::DSA 0.11 not found.
Warning: prerequisite Crypt::IDEA 0 not found.
Warning: prerequisite Crypt::RSA 1.37 not found.
Warning: prerequisite Digest::BubbleBabble 0.01 not found.
Warning: prerequisite Digest::HMAC_MD5 0 not found.
Warning: prerequisite Digest::HMAC_SHA1 0 not found.
Warning: prerequisite Digest::SHA1 2.10 not found.
Warning: prerequisite Math::GMP 1.04 not found.
Warning: prerequisite Math::Pari 2.001804 not found.
Writing Makefile for Net::SSH::Perl
以上訊息表示上面的模組都要裝
可以用 cpan -i model_name 去處理
全裝好後再下
#perl Makefile.PL
#make
#make install
這樣就安裝好了
以下用簡單的sample來說明 ssh模組的用法
用codes來說明
use Net::SSH::Perl ;
my $ssh = Net::SSH::Perl->new("IP_address");
$ssh->login("username", "passord");
#要執行的指令寫在此即可
$ssh->cmd("touch abc.txt");
全站熱搜
留言列表