title: Executing script requiring root access via CGI
body: <p>I have a script <strong>script.py</strong> which I'm able to execute via CGI by navigating to <em>mydomain.com/runscript</em>.</p>
  
  <p>The script however makes a subprocess call to <strong>echo "mysqldump ..." | sudo -i</strong> and <strong>sudo python</strong> using <strong>os.system(COMMAND)</strong>. When I attempt to run the script via the weblink, I get this error in <em>/var/log/apache2/error.log</em>:</p>
  
  <blockquote>
    <p>[Fri Jul 29 16:52:42.515223 2016] [cgi:error] [pid 3013] [client ##.###.##.##:#####] AH01215: sudo: no tty present and no askpass program specified</p>
  </blockquote>
  
  <p>This is because CGI runs as user <strong>www-data</strong>, which doesn't have sudo permission.</p>
  
  <p>I've tried adding this to my <strong>sudoers</strong> file:</p>
  
  <pre><code>%www-data    ALL = (root) NOPASSWD: /var/www/html/scripts/script.py
  </code></pre>
  
  <p>however the errors persist. Why are the subprocess calls not receiving root access, and how can I give it to them and ONLY them? Thank you!</p>