title: How can I call a .sh script from Django, considering permissions?
body: <p>Using, Django I would like to be able to pull changes from a github repository using a view to a development server for testing. This is on the ubuntu operating system, and I am using the Apache webserver. </p>
  
  <p>I've made a small <code>.sh</code> script called <code>gitpull.sh</code>. The contents of this file are:</p>
  
  <pre><code>#!/bin/sh
  cd /home/myrepo
  env -i /usr/bin/git pull origin master
  </code></pre>
  
  <p>The permissions on this file are:</p>
  
  <pre><code>-rwxrwxrwx  1 www-data www-data   64 Mar 10 01:19 gitpull.sh
  </code></pre>
  
  <p>If I create a python shell, I can run this using the following command:</p>
  
  <pre><code>import os
  os.system('/home/myrepo/gitpull.sh')
  </code></pre>
  
  <p>This works fine, and the repository pulls the most recent changes. I've also created a Django view that does the following:</p>
  
  <pre><code>import os
  def hook(request):       
  
      os.system('/home/courb/gitpull.sh')
  
      template = loader.get_template('git.html')
      context = RequestContext(request)
  
      # Return output objects with template
      return HttpResponse(template.render(context))
  </code></pre>
  
  <p>The problem I am having is that it is not pulling from the repository as I expected. I think it must be a permissions issue, but I thought apache/Django were part of the <code>www-data</code> group.</p>
  
  <p>I did also try to use gitPython in the following way </p>
  
  <pre><code>import git
  g = git.cmd.Git('/home/myrepo/')
  g.pull()
  </code></pre>
  
  <p>but I had an error message about the connection being terminated. I thought the <code>.sh</code> script might be an easier way to fix this problem.</p>