Question

I have written my first shell script which goes like this

#!/bin/bash
#
# This is a custom post-commit for sending email
# when an svn repo is changed.
#

repodir=$1
revision=$2

author=`/usr/bin/svnlook author  -r $revision $repodir`
date=`/usr/bin/svnlook   date    -r $revision $repodir`
log=`/usr/bin/svnlook    log     -r $revision $repodir`
info=`/usr/bin/svnlook   changed -r $revision $repodir`

url="http://www.mydomain.net/svn/filesystem/$repo"

echo 'To: me@googlemail.com' > commit-message   **<<LINE17**
echo 'From: me@mydomain.net' >> commit-message
echo 'Subject: SVN Commit' >> commit-message
echo '' >> commit-message
echo 'repository  -  $url' >> commit-message
echo 'date        -  $date' >> commit-message
echo 'username    -  $author' >> commit-message
echo 'revision    -  $revision' >> commit-message
echo 'comment     -  $log' >> commit-message
echo 'test email' >> commit-message
echo '$info' >> commit-message

ssmtp me@googlemail.com < commit-message

rm commit-message

When i run a test (with the svn vars stripped out) logged in as me on the server: ./post-commit
The script runs fine, it writes the commit file to disk and uses in conjunction with sSMTP, and i receive an email in gmail.

However when I commit a file with svn I am getting permission errors.

The thing is I have chmod'd the parent dir to 777.

post-commit hook failed (exit code 1) with output:
/home/svn/filesystem/hooks/post-commit: line 17: commit-message: Permission denied

When I try to see which user is running commits by wiping the post-commit script to:

echo $USER

It doesn't return anything.

Was it helpful?

Solution

Instead of using a temporary file just use a here document instead. Also, using single quotes won't allow your variable to be expanded:

ssmtp me@googlemail.com <<EOF
To: me@googlemail.com
From: me@mydomain.net
Subject: SVN Commit

repository  -  $url
date        -  $date
username    -  $author
revision    -  $revision
comment     -  $log
test email
$info
EOF

The problem by the way because the svn user has no write access to your current directory, or probably another directory on runtime.

More info about here documents here, and more info about quoting here.

A here string is actually another similar solution but I believe a here document is more appropriate here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top