実用裏方 Perl 入門

download 実用裏方 Perl 入門

If you can't read please download the document

description

標準モジュールで作るUNIXコマンドとバッチ処理

Transcript of 実用裏方 Perl 入門

  • 1. Perl
    UNIX
    keroyonn / Hokkaido.pm
    Hokkaido.pm #4
  • 2.
    ID
    cpan: keroyonhttp://search.cpan.org/~keroyon/
    github: keroyonnhttp://github.com/keroyonn
    twitter: keroyonn_http://twitter.com/keroyonn_
    hatena:keroyon0630http://d.hatena.ne.jp/keroyon0630
    Hokkaido.pm #4
  • 3.




    FTP

    !!
    Hokkaido.pm #4
  • 4.
    Hokkaido.pm #4

  • 5.

    (1)


    ()




    Hokkaido.pm #4
  • 6.

    cron

    JP1
    hinemosNTT

    Hokkaido.pm #4
  • 7. (1/3)

    ////DB

    /


    Hokkaido.pm #4
  • 8. (2/3)



    (1)
    Hokkaido.pm #4
  • 9. (3/3)

    (webalizer)

    Hokkaido.pm #4
  • 10.





    CPUIO

    Hokkaido.pm #4
  • 11.
    Hokkaido.pm #4

  • 12.
    ( cron + find OK)
    *.bak (cron + find OK)
    3 ( find )
    ()
    UNIX ()
    ()
    Hokkaido.pm #4
  • 13.
    corelist
    find
    corelist v 5.8.8 | egrep i file|find

    corelist v 5.8.8 | egrep i opt
    Hokkaido.pm #4
  • 14. (1/3)
    !!
    #!/usr/bin/perl
    use warnings;
    use strict;
    use utf8;
    use Getopt::Long;
    use Pod::Usage;
    use File::Find;
    use File::stat;
    BEGIN { binmode STDOUT, ':utf8; }
    #
    my $modified_time = 6;
    GetOptions( 'mtime=i' => $modified_time, ) or pod2usage(2);
    my $base_dir = shift @ARGV;
    if ( !defined $base_dir ) {
    print "n";
    pod2usage(2);
    }
    # bak
    find( &delete_files, $base_dir );
    Hokkaido.pm #4
  • 15. (2/3)
    sub delete_files {
    my $fullpath = $File::Find::name;
    my $filename = $_;
    # bak
    return if $filename !~ m{.bak$}xms;
    # n
    my $stat = stat($fullpath);
    my $mtime = $stat->mtime;
    return if $mtime + $modified_time * 3600 > time;
    #
    my $ret = unlink $fullpath;
    if ( $ret < 1 ) {
    print STDERR "$fullpathn";
    return;
    }
    print "$fullpathn";
    }
    Hokkaido.pm #4
  • 16. (3/3)
    __END__
    =encoding utf-8
    =head1 NAME
    delete_backup_files - n
    =head1 SYNOPSIS
    delete_backup_files [options] directory_name
    Options:
    --mtime=n n 6
    Hokkaido.pm #4
  • 17.
    touch
    touch t MMDDhhmm
    . hoge.txt 2/10 10:30
    touch t 02101030 hoge.txt
    Hokkaido.pm #4
  • 18.
    crontab e

    ** * * *
    30 3 * * 0 /home/hogehoge/delete_backup_files
    .
    1330
    3031 * *

    * * * * 0

    * * * * *
    Hokkaido.pm #4
  • 19.
    Perl Linux Perl
    -> corelist (Module::CoreList)

    -> Devel::Leak::Object

    -> Devel::NYTProf
    Hokkaido.pm #4
  • 20.
    Hokkaido.pm #4