2013年9月20日 星期五

[perl] How to connect to server by using ssh


[perl] How to connect to server by using ssh



#!/usr/bin/perl



use Net::SSH::Expect;



my $ssh = Net::SSH::Expect->new (

        host => "172.30.144.226",

        port => "22",

        user => "ubee",

        password => "ubee1234",

        raw_pty => 1,

        timeout => '20',

        #log_file => "$TempLogFile"

        );



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



if ($login_output !~ /nl-ams99z-cnr7/) {

        die "Login has failed. Login output was $login_output";

};



$ssh->exec("cd /tftpboot/66");

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



print "@Output\n";



$ssh->close();



Reference :



Related Posts:

0 意見:

張貼留言