Perl에서 더 좋은 모듈을 발견하지는 못해서, 일일이 파일 사이즈를 모두 더해서 폴더 사이즈를 구하였다. 그래서 시간이 좀 걸린다.

첫번째 방법
use v5.10;
use strict;
use warnings;

use File::Find;

sub get_folder_size {
    my ($dst_folder) = @_;
    my $folder_size = 0;
    find( sub { $folder_size += -f $_ ? -s _ : 0 }, $dst_folder );

    return $folder_size;
}

say "Folder Size : ".get_folder_size("C:\\");


두번째 방법

# ------------------------------------------------------------------------------
# 필요한 모듈 : cpanm -n File::Find::Object 
# ------------------------------------------------------------------------------
use v5.10;
use strict;
use warnings;

use File::Find::Object;

sub get_folder_size {
    my ($dst_folder) = @_;
    my $folder_size = 0;

    my $tree = File::Find::Object->new({}, ($dst_folder));
    while(my $file = $tree->next()) {
        next unless -e $file; # 존재하지 않으면 다음
        next unless -f $file; # 일반파일이 아니면 다음
        next unless -r $file; # 
        next unless -R $file; # 
        $folder_size += -s $file;
    }

    return $folder_size;
}

say "Folder Size : ".get_folder_size("C:\\");


http://mojoexample.herokuapp.com/ 에 Mojolicious 의 아주 좋은 샘플을 만들어 놓았지만, 2년전에 만들어져서 최신 버전에서 실행하려면 약간의 문제를 일으킵니다. 이를 조금 수정해서 제대로 돌아가게 해보았습니다.

Install MojoExample
$ cpanm -n Mojolicious Modern::Perl DBIx::Class DateTime DateTime::Format::SQLite Time::Duration File::Slurp SQL::Translator
$ git clone https://github.com/tempire/MojoExample.git /opt/project/project_name


바로 실행하면 에러가 발생하며, script/mojo_full의 마지막 줄을 아래와 같이 수정해주어야 합니다

...

# Mojolicious::Commands->start; # 2012년 버전에는 존재하였으나, 지금(2014년)은 사라짐.
Mojolicious::Commands->start_app('MojoFull');

start.sh 생성
# nohup morbo -m production -l http://*:8080 script/mojo_full &
morbo -m development -l http://*:8080 script/mojo_full

실행
$ ./start.sh

이제 입맛대로 고쳐서 원하는 사이트를 만들어봅시다. ^^


올해 들어서 벌써 2번째 해킹사고가 발생하였다. 한번은 exim 이라는 SMTP를 통해서, 그리고, 어제는 apache+php 를 통해서 이루어졌다. 각기 다른 서비스를 통해서 당했지만, 해킹 형태는 비슷하였다. 해당 서비스의 취약점을 통해서 /tmp 디렉토리에 perl 스크립트를 심고, 데몬으로 돌려서 특정 사이트에 과다 트래픽을 발생시켜서 마비시키는 것이었다.

이를 해결하는 방법으로는 아래 소개한 여러 복잡한 방법이 있지만, 공통점은 perl 을 이용한다는 것이므로, 가장 간단한 방법은 perl을 삭제하여 없애버리는 것이다. ^^; Simple is Best ???

좀 더 구체적인 방법에 대한 연구는, 시간을 내서 다시 한 번 시도해봐야겠다. 일단 여기에서는 기록 차원에서 글을 남긴다.

CentOS 5.6 에 기본으로 설치되어 있는 Perl 의 버전은 5.8.8 이다. 버전이 낮아도 한참 낮다. 요즘 다른 OS에는 5.10을 기본으로 사용하도록 되어 있으며, 최신 버전은 5.12 이다. 거기에 벌써 5.14 RC 버전까지 나온 상태이다. 이런 구닥다리 버전을 벗어나서 그나마 남들도 쓰는 버전을 쓰려면, 별도로 Perl 을 설치해야 되는데... 직접 소스 파일을 다운로드하여 컴파일/설치 하는 것도 방법이겠지만... 더욱 유연하고 확장성 있는 방법을 소개하고자 한다. 지난번 pythonbrew 를 이용해서 여러 버전의 python 을 설치하는 법을 알려드렸는데, 이것의 원조인 perlbrew 를 이용하면 우리가 원하는 것을 할 수 있다.

  1. 먼저 perlbrew를 설치한다.
    $ curl -Lk http://xrl.us/perlbrewinstall | bash
    
    설치를 완료하면 ~/perl5/perlbrew 가 생성된다. 그리고, 여기에 모든 파일들이 들어있다.
  2. .bashrc 에 다음을 추가한다.
    source ~/perl5/perlbrew/etc/bashrc
    
  3. Perl 5.12.3 설치해보기
    $ . .bashrc
    $ perlbrew install --force perl-5.12.3
    
  4. Perl 5.12.3 사용해보기
    $ perlbrew use perl-5.12.3
    $ perl -v
    
    This is perl 5, version 12, subversion 3 (v5.12.3) built for i686-linux
    
    Copyright 1987-2010, Larry Wall
    
    Perl may be copied only under the terms of either the Artistic License or the
    GNU General Public License, which may be found in the Perl 5 source kit.
    
    Complete documentation for Perl, including FAQ lists, should be found on
    this system using "man perl" or "perldoc perl".  If you have access to the
    Internet, point your browser at http://www.perl.org/, the Perl Home Page.
    
  5. Perl 시스템에 설치된 원래 버전 사용하기
    $ perlbrew off
    
    perlbrew is switched off. Please exit this shell and start a new one to make it effective.
    To immediately make it effective, run this line in this terminal:
    
        exec /bin/bash
    
    $ perl -v
    
    This is perl, v5.8.8 built for i386-linux-thread-multi
    
    Copyright 1987-2006, Larry Wall
    
    Perl may be copied only under the terms of either the Artistic License or the
    GNU General Public License, which may be found in the Perl 5 source kit.
    
    Complete documentation for Perl, including FAQ lists, should be found on
    this system using "man perl" or "perldoc perl".  If you have access to the
    Internet, point your browser at http://www.perl.org/, the Perl Home Page.
    
  6. perl-5.12.3 을 default Perl 로 설정하기
    $ perlbrew switch perl-5.12.3
    Switched to perl-5.12.3
    

+ Recent posts