#!/usr/local/bin/expect # wrapper to make passwd(1) be non-interactive # password file is passed as argv 0, username as 2nd, password as 3rd set passwordFile [lindex $argv 0] set username [lindex $argv 1] set password [lindex $argv 2] send_user "$passwordFile $username $password\n" spawn htpasswd -c $passwordFile $username expect "password:" send "$password\r" expect "password:" send "$password\r" expect eof