1

I've got a ruby cgi script which calls a shell script.

The shell script does a git pull.

When I run the shell script from the command prompt it works.

But when I run it from the ruby cgi script it executes the script but the git pull doesn't happen.

I'm guessing it's possibly permissions related but I can't quite work out how to fix it.

The ruby script is:

#!/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby
require "cgi"
git_pull = `sh /github/do_git_pull.sh`
move_apanels = `sh /github/move_apanels.sh`

puts "Content-type: text/html\n\n"
puts "<html><body>We've done the following:<ul>"
puts "<li>#{git_pull.to_s}</li>"
puts "<li>#{move_apanels.to_s}</li>"
puts "</ul></body></html>"

And the shell script is:

#!/bin/bash
sudo sh -c cd /github
sudo sh -c git pull origin master
echo "Git Pull Completed"

Both files have chmod 777

Any ideas?

2 Answers 2

2

Doing this:

sudo sh -c cd /github

only changes the PWD for the duration of that sh command. It does not affect the current shell. You need to cd and git pull in the same subshell:

sudo sh -c 'cd /github && git pull origin master'
Sign up to request clarification or add additional context in comments.

Comments

-1

Setting 777 on your scripts won't cut it. Try and find out the user under which your ruby script executes the shell script. Since git uses SSH keys for authentication and normally your SSH keys can only be used by you, then git pull would fail if another user tries to do the git pull.

Check out this question on how to run a shell script as a different user.

Also make sure that the PATH in the target environment is set properly and accessible (if you run the web server chrooted).

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.