3

I have this in post-commit:

#!/bin/sh

REPOS="$1"
REV="$2"

/usr/bin/php /home/name/svn/scripts/post-commit.php $REPOS $REV

But whatever I do, post-commit.php isn't being executed, not even with a chmod a+rw on it. Also there is no output from exec.

What am I missing?

Update: removed exec > ./logs/log.txt from this example since it seems to confuse people.

3 Answers 3

1

try:

#!/bin/sh
REPOS="$1"
REV="$2"

#debug:
echo "------------------------------"
date >> /tmp/debug.txt
echo "$@" >> /tmp/debug.txt
id >> /tmp/debug.txt
env >> /tmp/debug.txt

/usr/bin/php /home/name/svn/scripts/post-commit.php "$REPOS" "$REV" > /full/path/to/log.txt 2>&1

Also, verify that your post script works fine when executed by hand.

Sign up to request clarification or add additional context in comments.

8 Comments

Made the change. By hand it works, on commit it fails (post-commit hook failed (255 with no input)) :(
If it works by hand, then it's probably issue with perms or environment. Study debug output (see updated post). The 255 exit code is usually in fatal error like syntax error.
This is the output: Sun Sep 11 08:33:05 CDT 2011 /home/name/svn/xxx 37 uid=32289(the_user) gid=32292(the_user) groups=32292(the_user) PWD=password SHLVL=1 _=/bin/env What does this tell you? (I'm not sure what this means)
When executed from the command line the debug information contains a lot more variables. Does this mean anything?
From the command line there's this: _=/usr/bin/env While from the post-commit it's _=/bin/env
|
1

exec replaces the current shell process, and doesn't start a new one. So after the exec command, your shell stops.

The purpose of your particular exec command eludes me by the way ... So just remove it and you should be fine.

3 Comments

No, it isn't that. I read somewhere that exec writes the output to a file so that's why it's there. post-commit.php isn't executed without the addition of exec. I have this problem in other bash scripts too where I try to execute a php file. It works fine from the command line though.
Right ... exec also seems to serve a dual-function in the ability to reset stdout to a file ... How very un-UNIX! Anyway ... How are you executing this hook? from your description, I suspect something is going wrong there, and not with the actual script.
It's executed on an svn commit.
0

you'd better to exec a 'cd' first, to a directory where you really want the shell to execute. i'm not sure the path SVN will have when running this, but of course your script have potential privilege problems

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.