CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): terzeron (microkid)
날 짜 (Date): 2002년 9월 27일 금요일 오전 10시 26분 08초
제 목(Title): Re: perl script 하나만 부탁


.gotmail이 다음과 같은 형식으로 되어 있습니까?
username = terzeron
password = 12
그리고 /usr/local/bin/gotmail --silent --only-new --mark-read -u terzeron -p 12
이런 식으로 실행되어야 하는 거죠?


#!/usr/bin/perl

$EXE = "/usr/local/bin/gotmail --silent --only-new --mark-read";

open(PASS, "/etc/passwd") or die "can't open passwd file";

# 패스워드 파일을 순차적으로 읽어서
while ($line = <PASS>) { 
    # :을 delimiter로 하여 필드를 잘라내어 아이디와 홈디렉토리 저장
    @field_list = split ":", $line;
    $username = $field_list[0];
    $home = $field_list[5];

    if ($home =~ /^\/home/ && -r "$home/.gotmail") {
        # 홈디렉토리가 /home으로 시작하고 .gotmail을 읽을 수 있으면 열어서
        open(GOTMAIL, "$home/.gotmail") or die "can't open .gotmail file";

        while (<GOTMAIL>) {
            # 해당 패턴을 검사
            $arg1 = "-u $1" if /^username\s*=\s*([A-Za-z0-9]+)/;
            $arg2 = "-p $1" if /^password\s*=\s*(\S+)/;
        }
        # 실행
        exec("$EXE $arg1 $arg2") if ($arg1 && $arg2);
    }
}

---
어떤 성취가, 어떤 조롱이, 또는 어떤 고뇌가 나를 기다리고 있을지 나는 모른다. 
나는 아무 것도 모른다. 그러나 나는 아직 과거의 경이로운 기적의 시대가 영원히 
과거의 것이 되어 버리지는 않았다는 사실을 굳게 믿고 있다.  - Stanislaw Lem -
[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.