I would like to invoke a bash script (to do some rsync magic) towards the end of my post-commit hook.

Here is what my post commit hook looks like:




temp_dir="/var/www/vhosts/domain.com/temp"$(date +"%s")       # to avoid conflict, append unix timestamp



is_dev=`$SVNLOOK dirs-changed -r "$REV" "$REPOS" | grep -c "Dev"`
is_alpha=`$SVNLOOK dirs-changed -r "$REV" "$REPOS" | grep -c "trunk"`
is_beta=`$SVNLOOK dirs-changed -r "$REV" "$REPOS" | grep -c "Beta"`
is_live=`$SVNLOOK dirs-changed -r "$REV" "$REPOS" | grep -c "Live"`

# Export from svn to web root; save previous version in ???.project.com.bkp
if [ $is_dev -gt 0 ]; then
rev="$SVNLOOK youngest $repo_dev";

    svn export "$repo_dev" "$temp_dir" --force
    rm -rf "${webroot_dev}.bkp"
    mv -f "${webroot_dev}/" "${webroot_dev}.bkp"
    mv -f "$temp_dir" "$webroot_dev"
    date +%s > "${webroot_dev}/public/ex/config/version.txt"
    cp "/usr/local/bin/scripts/releases/override.dev.ini" "${webroot_dev}/public/ex/config/ini/override.ini"
    chown -R apache:apache "$webroot_dev"
    chown -R apache:apache "${webroot_dev}.bkp"
    cp -p -R "${webroot_dev}.bkp/public/uploads/avatars" "${webroot_dev}/public/uploads"
    sh /var/svn/Echo/hooks/testing.sh # -- THIS IS WHAT FAILS
elif  [ $is_alpha -gt 0 ]; then
    svn export "$repo_alpha" "$temp_dir" --force
    rm -rf "${webroot_alpha}.bkp"
    mv -f "${webroot_alpha}/" "${webroot_alpha}.bkp"
    mv -f "$temp_dir" "$webroot_alpha"
    date +%s > "${webroot_alpha}/public/ex/config/version.txt"
    chown -R apache:apache "$webroot_alpha"
    chown -R apache:apache "${webroot_alpha}.bkp"
    cp -p -R "${webroot_alpha}.bkp/public/uploads/avatars" "${webroot_alpha}/public/uploads"
elif [ $is_beta -gt 0 ]; then
elif [ $is_live -gt 0 ]; then

The script I am trying to call is "testing.sh", here is what the code looks like:

rsync -rtvu --cvs-exclude --delete /var/www/vhosts/domain.com/dev.project.com/ -e "ssh -i /var/svn/Project/hooks/testing.pem" ec2-user@ipaddress:/home/ec2-user/testing/

The error I am getting is the following:

post-commit hook failed (exit code 255) with output: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(463) [sender=2.6.8]

Update: This all works fine if I execute testing.sh manually from the same location. The host key error is only reported when the bash script is executed via the post-commit hook.

  • 1
    Which user is running the commit hook? Could this be a known_hosts prompt issue? You could try using the -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null as the ssh argument to deal with the prompt. – geedoubleya Oct 10 '14 at 10:17
  • @geedoubleya This worked! I actually only added the -o StrictHostKeyChecking=no and then did a cmod 400 on the pem file. Boom, working great. If you want to write up as answer I will accept. – Nicholas Kreidberg Oct 10 '14 at 13:29

During the ssh authentication, you may be prompted to add the host to your known_hosts file?

You can disable this by adding the command line option:

-o StrictHostKeyChecking=no

ssh man page extract:

ssh automatically maintains and checks a database containing identification for all hosts it has ever been used with.  Host keys are stored in ~/.ssh/known_hosts in the user’s
     home directory.  Additionally, the file /etc/ssh/ssh_known_hosts is automatically checked for known hosts.  Any new hosts are automatically added to the user’s file.  If a host’s
     identification ever changes, ssh warns about this and disables password authentication to prevent server spoofing or man-in-the-middle attacks, which could otherwise be used to
     circumvent the encryption.  The StrictHostKeyChecking option can be used to control logins to machines whose host key is not known or has changed.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.