Unable to run ruby script to git pull from github


I have a rails server running in my Ubuntu 14.04 instance and I host my code in For user’s pushing to github, I have setup a webhook to my app which listens to any POST call from github and tries to execute a ruby script gitscript.rb when the POST has all correct payloads.

Unfortunaltely the script doesn’t do a git pull and I am stumped to run this perfectly. Any help would be appreciated.

Below is my code to listen to webhooks and it runs the script, but the commands in the script don’t run, I have all the permission required for the ruby script.

def webhooks
    push = JSON.parse(
    if some_condition_that_should_be_true "Yes go ahead and pull" "Ran the git pull command" if `cd /home/server && git pull >> cat.txt` "Ran the ruby" if `ruby /home/server/gitscript.rb` "Last command"
    else push
    render :json => { :code => 'Webhooks came good' }, :status => 200

And my ruby script is below and yes it has all permissions correct, for test sake I made them 777

#!/bin/env ruby
`cd /home/server && git pull`

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Have you tried running the script manually to see if there are any errors?

One thing I notice is that, at least on Ubuntu, the shebang line is wrong.

/bin/env: bad interpreter: No such file or directory

You want to use:

#!/usr/bin/env ruby

Also, make sure you are pulling from GitHub using the https url and not the git@ one. You can check this by running:

git remote show origin

If the fetch url looks like:

Fetch URL:

It might be failing as it is will try to connect over SSH. If that’s what you want to do, you’ll need to create an SSH key on the server without a password so that the script doesn’t block waiting for you to enter it. You’ll also need to add the public key to your GitHub account.