2009-05-11 10 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

を使用してください。 'export TMPDIR ="/tmp/space test "を試してください。 ./Toolfile'のための+1、それを知らなかった –

1
  1. 私の現在のバージョン。 mktempを使用すると、はるかに安全です。
  2. "cd $ REPOSITORY"の代わりにcd "$REPOSITORY"にするか、REPOSITORYにスペースや特殊文字が含まれていると面白くなります。
  3. 自動コミットコメントを書くべきではありません。このトピックに関する偉大な記事はSee hereです。
  4. hgはおそらくstderrにエラーを出力します。あなたが適切と10行目は$リポジトリ/の.hgが引用されていない$ OUTPUT_LOGを引用していないhg commit -A -m "$comment" 2>&1hg push 2>&1
+0

スクリプトは主に外部サーバからの監視目的の/ var/logと/ etcをバックアップしますが、自動化されたコミットコメントは、その目的には十分でなければなりません – Jeffrey04

関連する問題