DNのバックアップ

2012年11月26日 Perl
DNのバックアップをローカルに取る。
これをcrontabで毎日自動実行すればバックアップが取得できる。
#!/user/bin/perl
use strict;
use warnings;
use LWP::UserAgent;

my $UserAgent = LWP::UserAgent->new;
# TimeOut
$UserAgent->timeout(8);

# Proxy
=pod
my $http_proxy = "[server]:[port]";
$ENV{HTTP_PROXY} = $http_proxy;
$ENV{HTTPS_PROXY} = $http_proxy;
$UserAgent->protocols_allowed(undef);
$UserAgent->env_proxy;
=cut

# Test URL
my $response = $UserAgent->get(’[URL]’);

if($response->is_success){
  my @array_time = localtime(time);
  $array_time[3] = sprintf("%02d",$array_time[3]);
  $array_time[4] = sprintf("%02d",$array_time[4] + 1);
  $array_time[5] = sprintf("%04d",$array_time[5] + 1900);  
  my $content = $response->content;
  open(FH,">> $array_time[5]$array_time[4]$array_time[3].html");
  print FH $content;
  close(FH);
}else{
  die $response->status_line;
}

exit;

プロキシ設定が必要な場合はプロキシ設定箇所のコメントアウトを除外してサーバIPとポート番号を指定する。あとはURLを自分のDNのURLに置き換えればOK。

コメント

最新の日記 一覧

<<  2025年6月  >>
1234567
891011121314
15161718192021
22232425262728
293012345

お気に入り日記の更新

この日記について

日記内を検索