title: Using expect in Perl with system()
body: <p>I am trying to use <code>expect</code> using system calls in a Perl script to recursively create directories on a remote server. The relevant call is as follows:</p>
  
  <pre><code>system("expect -c 'spawn  ssh  $username\@$ip; expect '*?assword:*' {send \"$password\r\"}; expect '*?*' {send \"mkdir -p ~/$remote_start_folder/$remote_folder_name/$remote_username/$remote_date/\r\"}; expect '*?*' {send \"exit\r\"};  interact;'");
  </code></pre>
  
  <p>This works fine. However, if it is the first time that the remote amchine is accessed using <code>ssh</code>, it asks for a <code>(yes/no)</code> confirmation. I don't know where to add that in the above statement. Is there a way to incorporate it into the above statement(using some sort of <code>or</code>-ing)?</p>