2009-05-11 2 views
0

이것은 이전 스크립트에 대한 작은 추가 작업이며 이번에는 백업에 대한 세부 정보를 기록하고 싶습니다.로깅 수은 거래

script /tmp/commit-push-log 

# add all files to the repository 
for REPOSITORY in [email protected] 
do 

    cd $REPOSITORY 

    # commit the changes 
    hg commit -A -m "Commit changes `date`" 

    # push the changes to the remote repository 
    if hg push 
    then 
     logger hg push completed without failure 
    else 
     logger hg push fails 
    fi 

done 

exit 

cat /tmp/commit-push-log | logger 

rm /tmp/commit-push-log 

문제는 로그에 아무런 메시지도 표시되지 않는다는 것입니다. 스크립트에서 어떤 점이 잘못 될 수 있습니까?

답변

1

당신은 정적 TMP 파일 이름을 사용해서는 안

for REPOSITORY in [email protected] 
do 

    # new temp file 
    OUTPUT_LOG=`tempfile` 
    echo -n > $OUTPUT_LOG 

    # checks whether $REPO is a repo 
    if [ ! -d $REPOSITORY/.hg ]; then 
     echo "Not a repository: $REPOSITORY" 
     exit 1; 
    fi 

    # change to that dir 
    cd "$REPOSITORY" 

    logger "Repository: $REPOSITORY" 

    # commit the changes 
    hg commit -A -m "Commit changes `date`" 2>&1 >> $OUTPUT_LOG 

    # push the changes to the remote repository 
    if hg push 2>&1 >> $OUTPUT_LOG 
    then 
    logger hg push completed without failure 
    else 
    logger hg push fails 
    exit 1; 
    fi 

    # log the contents and delete the tempfile 
    cat $OUTPUT_LOG | logger 

    rm -f $OUTLOG_LOG 

done 

exit 0 
+0

$ OUTPUT_LOG를 올바르게 인용하지 않았으며 $ REPOSITORY/.hg는 따옴표로 묶지 않았습니다. 'export TMPDIR = "/ tmp/space test"를 시도해보십시오. ./Mykdir "$ TMPDIR"; ./ Your_script' # 내가 의미하는 바를 보자. +1은'tempfile '에 대해 알지 못했다. –

1
  1. 내 현재 버전. mktemp를 사용하면 훨씬 안전합니다.
  2. "cd $ REPOSITORY"대신 cd "$REPOSITORY"을 입력해야합니다. 그렇지 않으면 REPOSITORY에 공백이나 특수 문자가 포함될 때 재미있는 일이 생깁니다.
  3. 자동 커밋 주석을 쓰면 안됩니다. 이 주제에 대한 훌륭한 기사는 See here입니다.
  4. hg은 아마도 stderr에 오류를 출력합니다. hg commit -A -m "$comment" 2>&1hg push 2>&1
+0

스크립트는 주로/var/log와/etc를 외부 서버로부터 모니터링 목적으로 백업한다. 자동 커밋 주석은 목적에 충분해야합니다. – Jeffrey04