Logging operations

this is a small addition to the previous script and this time I would like to write the data for backup.

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

      

the problem is I don't see any mercurial messages in the log. What could be going wrong in my script?

0


a source to share


2 answers


my current version



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

      

+1


a source


  • You cannot use static tmp file names. Use mktemp, it is much safer.
  • You should cd "$REPOSITORY"

    instead of "cd $ REPOSITORY", or it will be funny if REPOSITORY contains spaces or special characters.
  • You shouldn't write automatic commit comments. See here for an excellent article on this topic.
  • hg probably prints errors to stderr. Use hg commit -A -m "$comment" 2>&1

    andhg push 2>&1



+1


a source







All Articles