IT Study/script

perl ssh 원격 명령 스크립트

겸겸사 2014. 10. 21. 17:21

#!/usr/bin/perl


my($host, $username, $password);

$host="서버IP";

$username="root";

#$password="";



use strict;

use Net::SSH::Perl;


my @KEYFILE = ("/root/.ssh/id_rsa");

my $ssh = Net::SSH::Perl->new($host, debug=>0, identity_files=>\@KEYFILE);

$ssh->login($username);


my($local_dir, $local_filename, $remote_dir, $remote_filename);

#$remote_dir = "/home/ruis";

#$remote_filename = "passwd";

$local_dir = "/root/perl";

$local_filename = "_httpd";


open FILE, "> $local_dir/$local_filename";

open FILE1, "> $local_dir/_uptime";


#print FILE ($ssh->cmd("cat $remote_dir/$remote_filename"))[0];

#print FILE ($ssh->cmd("cat /etc/sysconfig/network-scripts/ifcfg-eth0"))[0];

print FILE ($ssh->cmd("pstree"))[0];

print FILE1 ($ssh->cmd("uptime"))[0];


#$ssh->cmd("");


#### Perl ssh 원격접속 Test 파일 

#### 해당 파일을 기본골격으로 여러가지 원격 명령 Perl 파일이 생성가능


### Last version 20141021 ###