1

SVN 更新短信通知脚本

 2 years ago
source link: https://blog.yxwang.me/2009/06/svn-sms-notification/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

SVN 更新短信通知脚本

Tue, Jun 16, 2009 • Tooling

主要功能:开发人员执行svn commit后自动将开发人id、修订版本号和日志内容通过短信的方式通知所有人。

首先修改svn服务器对应项目目录hook/post-commit文件

#!/bin/bash

export LANG=en_US.utf8
REPOS="$1"
REV="$2"

cd /home/svn/repositories/sebank/hooks
./sms.py commit $REPOS $REV

注意别忘了这里的export LANG,我一开始测试的时候发现中文一直有乱码,后来才意识到shell的环境变量里缺这个。 hook/sms.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, urllib, os
from subprocess import *

user = 'your mobile number'
pword = 'fetion password'
phone = [
        '13764444444',
        '13813333333',
        ]

repo = sys.argv[2]
rev = sys.argv[3]
cmdlog = 'svnlook log -r %s %s'%(rev, repo)
cmdauthor = 'svnlook author -r %s %s'%(rev, repo)
log = Popen(cmdlog, stdout=PIPE, shell=True).stdout.read().strip()
author = Popen(cmdauthor, stdout=PIPE, shell=True).stdout.read().strip()

msg = 'sebank #%s %s: %s' % (rev, author, log)

for number in phone:
    url = 'http://sms.api.bz/fetion.php?username=%s&password=%s&sendto=%s&message=%s' % (user, pword, number, urllib.quote_plus(msg))
    cmd = 'curl "%s"' % url
    send = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    send.wait()

这里user是发送者的手机号,且该用户的飞信好友需包含其他用户,pword为飞信密码,phone为用户手机号码列表。 最后设置下这两个文件的权限,保证http/svn用户能执行即可。另外由于sms.py中飞信密码是明文保存的,注意控制它的读权限。

本作品采用知识共享署名-非商业性使用 3.0 版本许可协议进行许可,欢迎转载,演绎,但是必须保留本文的署名 zellux(包含链接),且不得用于商业目的。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK