2

Fair warning; I don't even really know Ruby. I'm just hacking together some scripts that I was given and hoping they'll work together.

Background

I'm using Ruby to automate several tasks as an svn administrator, and one of the tasks that I'm trying to effect is making a web-form that will automate the creation of a repository.

The script I'm running is about 100-200 lines total, including the includes and things like that. I'm sure there will be other problems with the code, but presently, it's running into one problem.

The Ruby script itself works. My problem is that it doesn't work when I try to call it from a PHP script in a different directory.

The directory structure is like this:

Home
    .www-docs
        makeRepo.php
    svn
        createNewRepo.php
        migrateOne.php // This has yet to cause a problem
        RepoUtils.rb // Not currently causing a problem

Problem

The exact problem that I'm running into is that the Ruby script stops executing (and doesn't print an error message that I can echo in the PHP at a particular point in the code.

I'm calling the script as follows:

chdir("../svn");
echo exec("ruby createNewRepo.rb $name1 $name2 $num")

So, it's definitely calling the script. I put print points throughout the script, so I know it stops around here:

print "Point 1"
acl = File.new(@@aclfile, "a")
print "Point 2"

@@aclfile is an absolute path, not relative, so I don't think that alone is the problem.

The above code will end up printing Point 1 (and nothing that comes after that, either).

What am I doing wrong?

Thanks!

3
  • 1
    chdir('..svn') is suspect. That should be chdir('../svn') if this is your real code. Commented Feb 25, 2013 at 1:12
  • 1
    This is most likely a permission problem. What user is the web server running under? That user will be used to run the Ruby script. If that user does not have access to the file or directory you're trying to access Ruby will exit with an exception that goes to stderror, which will not be visible in PHP. Commented Feb 25, 2013 at 1:34
  • @MichaelBerkowski Whoops, sorry, typo. :) Commented Feb 25, 2013 at 1:38

1 Answer 1

3

If it works when you run it by hand, but not through the PHP script, I'm thinking you've got a permissions problem. If the user that the web process is running as doesn't have access to the absolute path (or the path doesn't exist), you'll hit an error:

$ irb
1.8.7 :001 > File.new("/this/doesn't/exist", "a")
Errno::ENOENT: No such file or directory - /this/doesn't/exist
    from (irb):1:in `initialize'
    from (irb):1:in `new'
    from (irb):1
1.8.7 :002 > File.new("/etc/passwd", "a")
Errno::EACCES: Permission denied - /etc/passwd
    from (irb):2:in `initialize'
    from (irb):2:in `new'
    from (irb):2
1.8.7 :003 > 

Check your permissions on the target directory and determine whether the web user has access to it. For security reasons, I won't tell you to change the web user's permissions or to change permissions on the target directory. You'll have to make that call yourself.

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

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.