Cisco장비의 config을 자동으로 백업하기 위한 스크립트를 찾다가 perl module에 Net::Telnet::Cisco, net::Telnet::Cisco::IOS모듈을 사용하여 스크립트를 작성하는 방법을 찾게되었다.
아래의 스크립트는 aaa new-model이 적용되어서 username과 password를 통해서 로그인을 하지만 privilege level이 enable모드가 아니어서 enable mode로 전환하는 부분을 넣어주었다.
-----------
use POSIX;
use Net::Telnet::Cisco::IOS;

$BASEDIR = "/home/working";

chdir $BASEDIR;

$m_dir = strftime("%Y-%m",localtime);
if(!(chdir $m_dir)) {
mkdir $m_dir, 0755;
chdir $m_dir;
}

$username = "guest";
$password = "guest";

@host = qw( 192.168.10.80
);

foreach $host (@host) {
my $conn = Net::Telnet::Cisco::IOS->new(HOST=>$host);
$conn->login( Name => $username,
Password => $password); # aaa new-model을 사용하지 않는다면 Password항목만.

if(!$conn->enable($password)) { # Privilege level이 15라면 이 부분은 필요가 없을듯..
warn "Can't enable: ". $conn->errmsg;
}

@output = $conn->getConfig();
$outfile = ">".$host."-confg";
open(OUTFILE,$outfile);
print "Writing $host to file\n";
print(OUTFILE @output);
close OUTFILE;
$conn->close;
}

Posted by salgunamu
: