所有,
我想调用一个bash脚本(做一些rsync魔术)到我的post-commit hook结束。
这是我的后提交钩子看起来像:
#!/bin/bash REPOS="$1" REV="$2" SVNLOOK="/usr/bin/svnlook" AWK="/usr/bin/awk" temp_dir="/var/www/vhosts/domain.com/temp"$(date +"%s") # to avoid conflict, append unix timestamp webroot_dev="/var/www/vhosts/domain.com/dev.project.com" webroot_alpha="/var/www/vhosts/domain.com/alpha.project.com" webroot_beta="/var/www/vhosts/domain.com/beta.project.com" webroot_live="/var/www/vhosts/domain.com/project.com" repo_dev="file:///var/svn/Echo/branches/Dev" repo_alpha="file:///var/svn/Echo/trunk" repo_beta="file:///var/svn/Echo/branches/Beta" repo_live="file:///var/svn/Echo/branches/Live" 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 : fi
我试图调用的脚本是“testing.sh”,代码如下所示:
#!/bin/bash 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/
我得到的错误如下:
提交后挂钩失败(退出代码255),输出:主机密钥validation失败。 rsync:连接意外closures(迄今收到的0字节)[发件人] rsync错误:无法解释的错误(代码255)在io.c(463)[发件人= 2.6.8]
更新:这一切工作正常,如果我从相同的位置手动执行testing.sh。 只有在通过post-commit钩子执行bash脚本时才会报告主机键错误。
在ssh身份validation期间,可能会提示您将主机添加到known_hosts文件中?
您可以通过添加命令行选项来禁用它:
-o StrictHostKeyChecking=no
ssh手册页摘录:
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.