记录mercurial事务

记录mercurial事务,mercurial,shell,Mercurial,Shell,这是对上一个脚本的一个小补充,这次我想记录备份的详细信息 script /tmp/commit-push-log # add all files to the repository for REPOSITORY in $@ do cd $REPOSITORY # commit the changes hg commit -A -m "Commit changes `date`" # push the changes to the remote repos

这是对上一个脚本的一个小补充,这次我想记录备份的详细信息

script /tmp/commit-push-log

# add all files to the repository
for REPOSITORY in $@ 
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
问题是我在日志中没有看到任何mercurial消息。我的脚本中会出现什么错误?

我的当前版本

for REPOSITORY in $@ 
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
  • 您不应该使用静态tmp文件名。使用mktemp,它更安全
  • 您应该
    cd“$REPOSITORY”
    而不是“cd$REPOSITORY”,否则当存储库包含任何空格或特殊字符时,事情会变得有趣
  • 您不应该编写自动提交注释。关于这个主题的伟大文章
  • hg可能会向stderr输出错误。使用
    hg commit-A-m“$comment”2>&1
    hg push 2>&1

  • 该脚本主要用于备份/var/log和/etc,以便从外部服务器进行监控,因此自动提交注释应该足以满足您没有正确引用$OUTPUT\u log和第10行$REPOSITORY/.hg的目的。尝试导出TMPDIR=“/tmp/space test”;mkdir“$TMPDIR;。/你的脚本`#明白我的意思。
    tempfile
    的+1不知道那个。