Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4995677
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类: LINUX

2013-06-22 12:50:13

svn hooks 自动发邮件


在svn库中有一个目录是hooks


这个目录是当svn发生一定事件时触发的脚本


其中post-commit 就是当你commit时触发的


在这个目录中会有一些模板文件

正常生效是去掉模板的扩展名


svn 还存在一个svnlook命令

是用来查看svn库的信息的

或是你commit的信息


hooks里可以调用svnlook


下面就是我实现的方法


1.需要commit-email.pl

  这个文件可以网上下载

  我的附件中有我改后的

  修改

  

  #为注释  +为要加入的行 

  #my ($sendmail, $smtp_server);

  +my ($sendmail, $smtp_server,$uname,$upasswd);

  +$smtp_server = "mail.xxxx.com";

  +$uname="svn\@xxxx.com";

  +$upasswd="*********";

  

  #/usr/bin/sendmail

  

  ...............................................

  ...............................................

      elsif (defined $smtp_server and @email_addresses)

      {

        my $smtp = Net::SMTP->new($smtp_server);

+#qvb

+       handle_smtp_error($smtp, $smtp->auth($uname,$upasswd));

+#qvb add        

     handle_smtp_error($smtp, $smtp->mail($mail_from));

        handle_smtp_error($smtp, $smtp->recipient(@email_addresses));

        handle_smtp_error($smtp, $smtp->data());

        handle_smtp_error($smtp, $smtp->datasend(@head, @body));


2.vi mail-list.sh

 #!/bin/sh

 LIST="qvb3d@126.com  other@qq.com ";

 echo $LIST

 保存

 有多少邮箱都用空格 格开写在后面

 chmod +x mail-list.sh


3.安装 perl-GSSAPI  perl-Authen-SASL 两个包

  根据系统而定,安什么样的包

  如果没有,自己编译perl环境安装这两个包

  

4.vi post-commit


#!/bin/sh

# Subversion post commit hook

REPOS="$1"

REV="$2"

PROJ=`basename $REPOS`

MAILLIST=`/home/svn/data/hooks/mail-list.sh $REPOS $REV`

#echo $REPOS $REV >/dev/pts/0

/home/svn/data/hooks/commit-email.pl $REPOS $REV \

     --from "svn@xxx.com" --diff y -s "SVN: [$PROJ]" $MAILLIST


保存这里的目录都要指定绝对路径

echo $REPOS $REV >/dev/pts/0

这行是这测试用的

为了在ssh终端看到svn触发事件没有 要是本机你也可以改成/dev/console

一触发就会在屏幕上看到


5.可以编写测试脚本 test.sh

vi test.sh

#!/bin/sh


/home/svn/data/hooks/commit-email.pl  /home/svn/data 56 --from "xxxx@xxxx.com" --diff y -s "SVN: [data]" "xxxx@qq.com"

保存


chmod +x test.sh


注意上面的56是第多少次的commit

你可以改成1

有些邮件服务器是不能给自己发的,所以不要发给commit-email.pl中登录的smtp用户

data 就是库名


6.到邮箱收一下你的邮件


  看是不是,已经成功了

  

  前面的前提是,最好有一个自己的公司的smtp服务器

  

  目前 126 163 我没有测试


commit-email.zip


from:http://qvb3d.iteye.com/blog/1488209

阅读(1852) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~