我正在尝试自动在 .htpasswd 中为 Apache 设置用户密码,但这个脚本似乎并没有真正设置密码。我错过了什么?谢谢!
#!/bin/bash
PASSWORD=`tr -dc a-z0-9_ < /dev/urandom | head -c 10`
cat << 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"