title: set .htpasswd with bash expect
body: <p>I'm trying to automate setting a user's password in .htpasswd for Apache, but this script doesn't seem to actually set the password. What am I missing? Thanks!</p>
  
  <pre><code>#!/bin/bash
  
  PASSWORD=`tr -dc a-z0-9_ &lt; /dev/urandom | head -c 10`
  
  cat &lt;&lt; EOF | /usr/bin/expect
  spawn /usr/bin/htpasswd -c /var/.htpasswd testuser
  expect "assword:"
  send "$PASSWORD\r"
  expect "assword:"
  send "$PASSWORD\r"
  EOF
  
  echo -e "\nPassword set to: $PASSWORD\n"
  </code></pre>