title: Automate shell script which asks for password
body: <p>I have a complex shell script which calls various other scripts. Some command inside this scripts prompt for sudo password. I am writing a wrapper script to automate this.
  So, with online research I found the below things:</p>
  
  <ol>
  <li><p>Create a sudoer file with no passwords but it seems a list of commands have to be given for which this condition will apply. I don't want to search which command inside the scripts is invoking sudo password prompt because that would take too much time.</p></li>
  <li><p>Expect utility. This works with expect interpreter and i cannot spawn the script because spawn is a expect interpreter command. So, basically the below code works with expect:</p></li>
  </ol>
  
  <blockquote>
  <pre><code>#!/usr/bin/expect
  spawn sudo su
  expect "*assword"
  send "abc12\n"
  interact
  </code></pre>
  </blockquote>
  
  <p>but what I need is this:</p>
  
  <pre><code>#!/usr/bin/expect
  spawn ./complex_script.sh &lt;arg1&gt; &lt;arg2&gt;
  expect "*assword"
  send "abc12\n"
  interact
  </code></pre>
  
  <p>When I run this I get the below error:
  <em>couldn't execute "complex_script.sh": no such file or directory
      while executing
  "spawn complex_script.sh rootfs"
      (file "./a.sh" line 2)</em></p>
  
  <ol start="3">
  <li>echo password | script.sh also does not work.</li>
  </ol>
  
  <p>Thanks in advance.</p>